-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
revert broadening of arithmetic Any methods #45463
Comments
Not very ancient, #44564 :). The point was to make them generic (ref JuliaLang/LinearAlgebra.jl#905) |
Uy, why did we let that happen? On the other hand, I'm glad it's not that ancient since it means we can change it. |
It happened because of the discussion in JuliaLang/LinearAlgebra.jl#905 which was largely in favor of making the methods generic (I was (one of) the most skeptical ones). Then in #44564 I was begging for feedback, and received one approval and no strong objections, just some weak objections from @vtjnash.
Are you suggesting to resolve JuliaLang/LinearAlgebra.jl#905 by subtyping |
I agree that |
Do we want to add a |
Ideally a vector space (or group) trait: https://google-research.github.io/dex-lang/prelude.html#s-13 |
I strongly objected to #44564. I had already posted my objection in JuliaLang/LinearAlgebra.jl#905, and I had assumed I didn't need to re-post in #44564. |
I don't think that only |
No harm done here, @dkarrasch, I'd much rather you make forward progress on things and we occasionally have to revert something that not being able to get things done. |
If we really wanted to, we could define a new abstract type in -(x::Union{Number, AbstractArray{<:Number}, VectorSpaceElement}) = Int8(-1)*x Then, if you want to opt-in to these fallback methods for your custom type, and you don't want your custom type to be a subtype of Now, with that all being said, it's not clear to me why this |
PR #45320 removed a couple of
ancientrecent and dicey overly generic methods for arithmetic operators:+(x) = x
and*(x) = x
. But it left equally generic fallbacks like-(x) = Int8(-1)*x
and-(x, y) = x + (-y)
. I would argue that these should also require subtypingNumber
to opt into them. This is potentially a breaking change, but it seems weird to expect these things to work if your type isn't a number (and most other numbery things don't work). I would argue that the policy should be: if you don't subtypeNumber
then you don't get any arithmetic fallbacks, you only get fallbacks that truly make sense for all objects.Btw, several times people have insisted on specification of what the "interface for
Number
" is. There is no interface forNumber
, it is not an interface—there are no requirements that must be satisfied by aNumber
. WhatNumber
is, is a way to opt into a bunch of generic behaviors like these.The text was updated successfully, but these errors were encountered: