You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It often happens to wish to define a generic method, but that doing so would cause ambiguity warnings which are tedious to fix. Cf. #23433 and #23332 for recent PRs which delete such methods. In the Random module, it's also not easy to design usefully general functions (as fallbacks), which can apply to custom RNGs, but which don't get in the way of their implementors. One example:
rand(rng::AbstractRNG, ::Type{Float32}) = ... # in Base
rand(rng::CustomRNG, ::Type{T}) where {T<:Union{Float32,Float16}} = ... # in a package
What I proposed in #23332 would help in this case, but not if the Union above is replaced by AbstractFloat. So what about a new annotation to give lower priority to the method?
e.g:
@nice rand(rng::AbstractRNG, ::Type{Float32}) = ... # hey, if my signature becomes ambiguous, let's pretend I don't exist!
I wish I could make a prototype, but it would take me ages to understand the framework.
The text was updated successfully, but these errors were encountered:
This is a bit more subtle than it seems at first; for instance we might want the methods in #23433 to have higher priority to ensure that new float types don't lose the "strong zero" behavior. Or, the ambiguity error is at least useful for alerting people to the strong zero issue.
I can imagine cases where this feature would be useful, but it does add significant complexity.
Yes today I encounter a case where I would like to express "this method should have priority". In particular when defining a method on a concrete type I own. Maybe a second annotation @notnice with a better name would do it. I understand it can't be so easy to implement though.
It often happens to wish to define a generic method, but that doing so would cause ambiguity warnings which are tedious to fix. Cf. #23433 and #23332 for recent PRs which delete such methods. In the
Random
module, it's also not easy to design usefully general functions (as fallbacks), which can apply to custom RNGs, but which don't get in the way of their implementors. One example:What I proposed in #23332 would help in this case, but not if the
Union
above is replaced byAbstractFloat
. So what about a new annotation to give lower priority to the method?e.g:
I wish I could make a prototype, but it would take me ages to understand the framework.
The text was updated successfully, but these errors were encountered: