Hello, suppose I have the following types
abstract type Food end
struct Milk <: Food end
struct Berries <: Food end
struct Fish <: Food end
Now, I want to introduce a function mix
with 1) a default behavior for unknown subtypes of Food
and with 2) symmetry in the arguments.
For the 1) I could write this:
mix(A::Food, B::Food) = "don't know how to mix"
for the 2) I can go with:
mix(A:.Food, B::Food) = mix(B, A)
But I can’t use both at the same time. When follow up with this code:
mix(A::Milk, B::Berries) = "milk shake"
I can run
mix(Milk(), Berries())
mix(Berries(), Milk())
but not
mix(Fish(), Milk())
which ends up in the following:
ERROR: LoadError: StackOverflowError:
Stacktrace:
[1] mix(::Milk, ::Fish) at /media/DATA/PhD/code/ising/ising_julia_code/sandbox.jl:155 (repeats 80000 times)
while loading /media/DATA/PhD/code/ising/ising_julia_code/sandbox.jl, in expression starting on line 243
Is it possible to do it in a clever way without implementing
mix(A::Food, B::Something)
for each Something <: Food
type separately?
Thanks