Multiple dispatch: Force to use some certain method


#1

Is there any way to force the multiple dispatch system to use certain method instead of the less ambiguous one?

Here is a naive example

abstract type MyAbstract end

struct MyType1 <: MyAbstract 
    x::Int
end

struct MyType2 <: MyAbstract
    x::Float64
end

function foo(x::MyAbstract, y::MyAbstract)
    MyType2(x.x + x.y)
end

function foo(x::T, y::T) where T<:MyAbstract
    print("They were the same type!")
    foo(x::MyAbstract, y::MyAbstract) # This doesn't work yet
end

Thanks!


#2

Invoke:
https://docs.julialang.org/en/stable/stdlib/base/#Core.invoke


#3

That’s a good question!

I think some languages would call this the super function: