-
-
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
Ambiguity avoidance by "at least one" syntax for argument types #10440
Comments
The way to do this currently is to define both of these:
Then the first method will only be called with at least one This can be expressed with set operations as What I do plan to do is this: a method signature does not need to be a tuple of types. It can be any type that's a subtype of Tuple. So you should be able to use |
I should have pointed out that I'm aware of the current strategy and use it frequently. It's just that it's particularly awkward when (1) there are several kinds of But, making subtyping undecidable is not exactly a direction we want to go down, so I'll close this. I suppose we should do a little bit of refactoring of Base now, though, to make this easier. Probably the only sensible definition is getindex(A::AbstractArray, index::Real...) = getindex(A, to_index(index)...) That will result in a stack overflow if someone forgets to define function getindex(A::MyAbstractArray, index::Int...) but perhaps that's the least of all evils. |
I'm trying to define some new indexing methods, and running up against ambiguity warnings. Here's what I'm trying to do:
I want this function to be called only if there is at least one
SomeType
among theindex
arguments; otherwise the standard methods forReal
are just fine. As far as I can tell, we don't have a syntax for expressing this. Certainly,insists that the first index is a
SomeType
, but this isn't sufficiently flexible for my needs.How plausible would it be to implement this? As for syntax,
suggests itself (regex-like). If one had multiple options, then
seems natural.
The text was updated successfully, but these errors were encountered: