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

Tighten signature of iszero and isone fallbacks? #57372

Open
lgoettgens opened this issue Feb 12, 2025 · 1 comment
Open

Tighten signature of iszero and isone fallbacks? #57372

lgoettgens opened this issue Feb 12, 2025 · 1 comment
Labels
design Design of APIs or of the language itself

Comments

@lgoettgens
Copy link
Contributor

This originally came up in oscar-system/Oscar.jl#4574.

The fallback implementations of iszero and isone currently look like this:

iszero(x) = x == zero(x) # fallback method
isone(x) = x == one(x) # fallback method

This of course makes sense of x::Number, but there are a lot of other types defining a zero(::T) that is not that useful to be used in iszero(::T) like this.

I think a very prominent example would be iszero(Int) that compares Int with zero(Int) (which is 0) and returns false.

In the context of oscar-system/Oscar.jl#4574, the problem with this fallback is that people might try to use iszero(R::Ring) to check if R is the zero ring, but the fallback tries to compare R to the zero element in R. Since this is very similar to the Int case above, we wanted to mention this here to see if there is any chance to restrict the signature of the fallback method to something like ::Number. If there is no complete opposition against this, I could provide a PR implementing this, so that we could run a PkgEval so look for how breaking this change would be to the ecosystem.

cc @fingolfin

@fingolfin
Copy link
Member

Just to say, I believe in the library it would be sufficient to provide these for Number and AbstractArray (though I did not test this). But of course some packages might rely on this?

@nsajko nsajko added the design Design of APIs or of the language itself label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design of APIs or of the language itself
Projects
None yet
Development

No branches or pull requests

3 participants