-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mapreduce over &
on empty collection differs depending on type
#31635
Comments
I don't see what this could do differently. Yes, if we allowed reducing We did this deliberately, since without a value to pass to
This is not caused by type inference failing (which it isn't here). Rather it's caused by people's insistence on using |
Just so we are clear, you mean the Or something else? |
Yes. |
Now only |
To be pedantic, it's all I think this is getting closer to a sensible situation, and it largely mirrors what we do for other arithmetic reductions. For example: julia> sum(Int[])
0
julia> sum(Float64[])
0.0
julia> sum((0 for i in 1:0))
ERROR: ArgumentError: reducing over an empty collection is not allowed Now, one place where this still differs is in unions and other types. For example:
This is a fairly limited case; Since All that to say: this seems effectively complete. I'd say the only thing that remains would be that |
While regrettable that this can depend on type-inference in creating the empty case, the consistent alternative is to always error (requiring the |
I don't think it makes sense for a empty generator to throw an error,
and an empty
Array{Bool}
to not.Even more so, an empty
Array{Any}
to throw an error,Particularly when such typing can come about only due to type-inference failing
This weirdness related to
EltypeUnknown
being treated differently to having an eltype ofAny
.Perhaps in an ideal world, when type inference fails, the resulting Vector would have
EltypeUnknown
.But that is not a realistic solution.
Related: #28028
Return True:
Arrays that are typed
Bool
or successfully type inferredBool
Generators
Give Argument error about reducing over empty collection
Arrays not typed Bool
Type inference failures
The text was updated successfully, but these errors were encountered: