You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
julia> using FixedSizeArrays
julia> FixedSizeArrays.collect_as(FixedSizeVector, (n*n for n ∈1:0))
0-element FixedSizeVector{Any, Memory{Any}}
julia> collect((n*n for n ∈1:0))
Int64[]
We return an empty array with eltype of Any, while collect from Base returns an empty array with an element type of Int. Neither of these is ideal:
Any is obviously suboptimal
Int seems nice at first, but necessitates the use of return type inference. This is quite undesirable:
It inhibits compiler optimization AFAIK
in particular, the :foldable effect requires :nortcall
It makes the behavior depend on type inference, which makes for a terrible programming and debugging experience.
Unlike Base, we're not yet constrained by compatibility considerations, so I think we should:
avoid making our behavior depend on type inference (in particular, I think this means not doing things like map(identity, some_array) in the implementation of collect_as)
for empty input, we could do something like this:
set the output element type to Union{}, for an input element type equal to Any
set the output element type to the input element type, when it's not equal to Any