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

make prod(::Vector{Bool})::Int? #24425

Closed
StefanKarpinski opened this issue Oct 31, 2017 · 4 comments
Closed

make prod(::Vector{Bool})::Int? #24425

StefanKarpinski opened this issue Oct 31, 2017 · 4 comments

Comments

@StefanKarpinski
Copy link
Member

Came up over here: #24396 (comment). We already have sum([false,false,false]) === 0 but we have prod([true,true,true]) === true. I understand the logic that the value of the product can only be true or false so it might as well be of type Bool, but I think it makes sense that sum and prod return the same type; if someone really wants a Bool result, they can always use all.

@StefanKarpinski StefanKarpinski added the triage This should be discussed on a triage call label Oct 31, 2017
@ararslan
Copy link
Member

ararslan commented Nov 2, 2017

Personally I like the idea of deprecating sum and prod on collections with Bool elements in favor of count and all, respectively. (Though it may only make sense to do that if we didn't have Bool <: Integer, otherwise that would be a bit inconsistent.) Regardless, +1 for the proposed change here. Never mind, Jeff has a good point.

@StefanKarpinski
Copy link
Member Author

I don't think it's justifiable not to allow sum and prod on booleans unless they're made non-numbers – which we've already decided is too annoying and disruptive.

@JeffBezanson
Copy link
Member

-1. The same difference exists for the scalar operation:

julia> false+false
0

julia> false*false
false

I don't see much reason to introduce a different result type just because a reduction is being done.

@StefanKarpinski
Copy link
Member Author

Based on triage discussion, we seem to be at a local optimum, with booleans behaving as strong zero and strong one for multiplication whereas as long as booleans are numbers, summing them is useful. FWIW, Knuth is very pro strong zero as a concept: https://arxiv.org/abs/math/9205211.

@StefanKarpinski StefanKarpinski removed the triage This should be discussed on a triage call label Nov 2, 2017
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

No branches or pull requests

3 participants