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

zero() and one() for incomplete and abstract types #4808

Open
ivarne opened this issue Nov 14, 2013 · 8 comments
Open

zero() and one() for incomplete and abstract types #4808

ivarne opened this issue Nov 14, 2013 · 8 comments
Labels
breaking This change will break code maths Mathematical functions

Comments

@ivarne
Copy link
Member

ivarne commented Nov 14, 2013

The current state of zero and one seems unexpected for incomplete and abstract types. I think all these cases should result in an error.

julia> zero(Real)
0
julia> typeof(ans)
Int64

julia> one(Real)
1
julia> typeof(ans)
Int64

julia> zero(Complex)
0 + 0im
julia> typeof(ans)
Complex{Int64} (constructor with 1 method)

julia> one(Complex)
1 + 0im
julia> typeof(ans)
Complex{Int64} (constructor with 1 method)

Some relevant discussion in #3728, but I'm opening a new one because it is marked as fixed.

Edited to add:
I also want errors for arrays of incomplete and abstract types, but i have not figured out the relationship between zero and zeros and one and onses. That might be a separate issue.

@johnmyleswhite
Copy link
Member

+1 for making all of these errors.

@StefanKarpinski
Copy link
Member

I agree that these should be errors for abstract types.

@ivarne
Copy link
Member Author

ivarne commented Nov 14, 2013

@StefanKarpinski What about incomplete types like Complex{T<:Real}?

@StefanKarpinski
Copy link
Member

It seems like anything that's not a complete concrete type is problematic since, while you may be able to pick some zero value that's of that type, it's always somewhat arbitrary since there will be other ones that could be picked.

@Keno
Copy link
Member

Keno commented Apr 15, 2014

would zero(::Any)=false make sense?

@StefanKarpinski
Copy link
Member

Currently that only really makes sense for Number, not Any. I'm skeptical about one and zero for Any.

@jiahao
Copy link
Member

jiahao commented Apr 16, 2014

zero(::Any)=false isn't sensible for arrays.

@kshyatt kshyatt added error handling Handling of exceptions by Julia or the user types and dispatch Types, subtyping and method dispatch labels Sep 15, 2016
@tkelman tkelman removed the error handling Handling of exceptions by Julia or the user label Sep 15, 2016
@JeffBezanson JeffBezanson added maths Mathematical functions and removed types and dispatch Types, subtyping and method dispatch labels Apr 4, 2018
@goretkin
Copy link
Contributor

If this issue hasn't been discussed elsewhere, could it get a breaking label and perhaps a 2.0 milestone?

This came up in this thread recently: https://discourse.julialang.org/t/why-isa-x-1-y-1-array-tuple-stuff-number-1-false/55777

@brenhinkeller brenhinkeller added the breaking This change will break code label Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code maths Mathematical functions
Projects
None yet
Development

No branches or pull requests

10 participants