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

wishlist: tag a method to be discarded in case of ambiguity #23443

Open
rfourquet opened this issue Aug 25, 2017 · 2 comments
Open

wishlist: tag a method to be discarded in case of ambiguity #23443

rfourquet opened this issue Aug 25, 2017 · 2 comments
Labels
speculative Whether the change will be implemented is speculative

Comments

@rfourquet
Copy link
Member

rfourquet commented Aug 25, 2017

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.

@stevengj stevengj added the speculative Whether the change will be implemented is speculative label Aug 25, 2017
@JeffBezanson
Copy link
Member

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.

@rfourquet
Copy link
Member Author

rfourquet commented Aug 27, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
speculative Whether the change will be implemented is speculative
Projects
None yet
Development

No branches or pull requests

3 participants