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

Change one to onemult #36103

Open
timholy opened this issue Jun 1, 2020 · 8 comments
Open

Change one to onemult #36103

timholy opened this issue Jun 1, 2020 · 8 comments
Milestone

Comments

@timholy
Copy link
Sponsor Member

timholy commented Jun 1, 2020

This is a persistent source of confusion (most recently #36099), and there are incorrect definitions of one scattered across the ecosystem. (We're still deprecating them in Colors-world.) The best answer is to @deprecate one onemult and simply not have a function called one.

@timholy timholy added this to the 2.0 milestone Jun 1, 2020
@kimikage
Copy link
Contributor

kimikage commented Jun 1, 2020

What about adding the 2-arg identity(op, x)?

Edit
As you know, this comes from #16116.

@kimikage
Copy link
Contributor

kimikage commented Jun 1, 2020

I think onemult will just change the FAQ to "Why can I use zero but not one? It's inconsistent!" 😛

@timholy
Copy link
Sponsor Member Author

timholy commented Jun 1, 2020

What about adding the 2-arg identity(op, x)?

"Why is there oneunit but no zerounit?" 😛

@benninkrs
Copy link

benninkrs commented Jun 5, 2020

This ship has probably already sailed, but I've often thought that zero and one should be instances of singleton types Zero and One, representing the typeless concepts of additive and multiplicative identity with fallbacks like +(::Zero, x) = x and *(::One, x) = x. Related discussions: #8092, #16116, #18367, #20561.

@stevengj
Copy link
Member

but I've often thought that zero and one should be instances of singleton types Zero and One

This would make a lot of functions type-unstable. e.g. sum(T[]) returns zero(T), so returning Zero() instead would make sum type-unstable (since the type of the result would differ for empty vs. non-empty arrays of the same type).

@benninkrs
Copy link

benninkrs commented Jun 11, 2020

Of course if the type is known then one should return the zero element of that type. I’m thinking of cases where the type is not known.

But even if it were used in general, the return type would be Union{Zero,T}. I was under the impression such small unions are now reasonably performant.

@tkf
Copy link
Member

tkf commented Jun 12, 2020

Singleton zero is discussed in #34003. I also mentioned other identities there too.

I think it's better to focus on onemult in this issue.

@perrutquist
Copy link
Contributor

perrutquist commented Jun 29, 2020

How about deprecating to Base.reduce_empty(*, T) (which already exists) instead of onemult(T)? The only place where you really need this is as the return value of empty reductions.

In all other cases (that I can think of) you can either use true or oneunit.

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

6 participants