Basically a multi-method or a multi-dispatch method, in this case, is a
hash or dictionary
whose key is the tuple of the types of the input arguments and whose value
is the
implementation.
The problem with this scheme is, what if the key does not return an
implementation.
In your case you use the Union *Number* as a parameter type on the
non-parameterised
and for the parameterised function definition of foo.
Your parameterised definition has stronger binding, since julia is all to
multi-dispatching.
Well. There is a load of discussion about how to find a function that best
match.
This is all related to contravariance and covariance,
Basically you override the non-parametrised definition of foo.
interestingly, in C++, if I am a bit more specific. This behaves the way I
expect it should:
int foo(int a)
{
return 1;
}
template<typename T=int>
T foo(T a)
{
return 2;
}
And if i print this for *foo(2), foo(-1), foo(3.14)* I get: *1 1 2*
Which is exactly the same, if I define this in Julia.
So in conclusion I think, and please anybody correct me if i am wrong.
Mutli-Dispatch functions
are first class citizens when it comes to dispatching. That is why you get
these results.
I really hope this helps.
Stefan
{
return 1;
}