JuliaLang/julia
Auf GitHub ansehenunary `+` acts differently for `Array` and `AbstractArray`
Open
#58.295 geöffnet am 1. Mai 2025
arraysdesigngood first issue
Repository-Metriken
- Stars
- (48.709 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 23T 11h) (145 gemergte PRs in 30 T)
Beschreibung
(This issue is tangentially related to #58281.)
The return type of unary + with Bool argument is not the same for arrays and views:
julia> v = [true, false]; +v
2-element Vector{Int64}:
1
0
julia> w = view(v, :); +w
2-element view(::Vector{Bool}, :) with eltype Bool:
1
0
The reason is that unary + for AbstractArray is simply the identity map:
Hence it misses the convention that + transforms Bool to Int.
Another consequence of this definition is that one doesn't know whether +v is identical to v for mutable v:
julia> v = [1, 2]; +v === v
false
julia> w = view(v, :); +w === w
true
In my opinion, it would be good to have a consistent answer. However, it may be to late for that.