Skip to content

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

Open

Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    speculativeWhether the change will be implemented is speculative

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions