Skip to content
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

Implement reduce_empty(op, Union{}) #35843

Merged
merged 7 commits into from
May 23, 2020
Merged

Implement reduce_empty(op, Union{}) #35843

merged 7 commits into from
May 23, 2020

Conversation

tkf
Copy link
Member

@tkf tkf commented May 11, 2020

Interestingly, the invalidation hunt #35733 actually fixed a bug in reduce_empty. As #35733 may not be merged as-is, I extracted the bug fix part from #35733 and added a test to it.

It requires https://github.com/JuliaLang/Statistics.jl/pull/36

@tkf
Copy link
Member Author

tkf commented May 13, 2020

@timholy's feedback in JuliaLang/www.julialang.org#794 (comment):

I don't think that's a bug. We have lots of methods that result in an ambiguity error if you use Union{} as a type. Try zero, one, etc.

OK maybe saying it's a "bug" is too much. But I think it is a fault of the caller to invoke one(Union{}). I don't think it's a fault of caller to call sum(Union{}[]) because sum should handle any iterable object and give sensible error when it doesn't work. Union{}[] is a reasonable input for any function on iterables because it is the "zero" of the binary "operator" append!/vcat. So it's the "best" empty vector to use as the initial state for constructing a vector that might contain numbers of unknown type. I don't think revealing the internal gut when a reasonable input is given is ideal.

@tkf
Copy link
Member Author

tkf commented May 15, 2020

This also fixes a bug mentioned in #28777 (comment)

On Julia 1.6-DEV:

julia> reduce(*, ())
""

After this PR:

julia> reduce(*, ())
ERROR: ArgumentError: reducing over an empty collection is not allowed

Copy link
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Though note that since (as you showed) reduce(*, ()) == "" currently, making it throw an error may technically break some code.

@tkf tkf merged commit f705e60 into JuliaLang:master May 23, 2020
@tkf tkf deleted the reduce-bottom branch May 23, 2020 21:47
KristofferC pushed a commit that referenced this pull request May 25, 2020
simeonschaub pushed a commit to simeonschaub/julia that referenced this pull request Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants