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

Reduction with & should not widen the type #14897

Closed
eschnett opened this issue Feb 1, 2016 · 2 comments
Closed

Reduction with & should not widen the type #14897

eschnett opened this issue Feb 1, 2016 · 2 comments
Labels
collections Data structures holding multiple items, e.g. sets design Design of APIs or of the language itself maths Mathematical functions

Comments

@eschnett
Copy link
Contributor

eschnett commented Feb 1, 2016

This surprised me:

julia> typeof(reduce(&, Int8(0), (Int8(4),)))
Int32

It makes sense of + to widen the type to prevent overflow, but & cannot overflow. I tried to counteract the automatic widening by providing an explicit neutral element, but that didn't help.

I also notice that a + reduction widens Bool to Int64, while a & reduction does not widen it.

Should there be a widereduce in addition to reduce?

Should there be an optional argument T that lets people specify the return type?

@kshyatt kshyatt added the types and dispatch Types, subtyping and method dispatch label May 10, 2016
@JeffBezanson JeffBezanson added collections Data structures holding multiple items, e.g. sets design Design of APIs or of the language itself maths Mathematical functions and removed types and dispatch Types, subtyping and method dispatch labels Apr 4, 2017
@stevengj
Copy link
Member

See also #20607

@KristofferC
Copy link
Member

julia> typeof(reduce(&, (Int8(4); init=Int8(0))))
Int8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
collections Data structures holding multiple items, e.g. sets design Design of APIs or of the language itself maths Mathematical functions
Projects
None yet
Development

No branches or pull requests

5 participants