I am currently trying to come up with a function signature that would let me take an arbitrary number of 2-tuples where the types of the elements are not necessarily the same. I know that with the signature
function f(dom::Vararg{Tuple{T, T}, D} where {D, T <: Real}
...
end
I can dispatch on any number of tuples as long as their elements are all the same type. For instance, (-2.0, 2.0), (-1.0, 1.0) and so on.
I would like to catch elements of the form (-1, 1.0), (1, 1.0) for instance. If only to explicitly throw an argument error, but preferably to promote all the elements and call the type-stable method defined earlier.
I have tried with this signature
function f(dom::Vararg{<:Tuple{Real, Real}, D} where {D <: Real}
...
end
and
function f(dom::Vararg{<:Tuple{<:Real, <:Real}, D} where {D <: Real}
...
end
But I get this error when trying to call it
julia> f((1.0, 1), (1.0, 1.0)
ERROR: MethodError: no method matching f(::Tuple{Float64, Int64}, ::Tuple{Float64, Float64})
Closest candidates are:
f(::Tuple{Real, Real}...) where D <: Real
@ REPL
f(::Tuple{T, T}...) where {D, T <: Real}
@ REPL
I have read the documentation on diagonal types, but I couldn’t come up with the correct signature myself.