You misunderstand me. I am not asking for julia implementation of pattern matching. I am asking about the relation between multiple dispatch and pattern matching…
Dispatch works on types, pattern matching on values. At least from your examples given.
So the latter can be implemented with value types as linked above, at the expense of possibly creating one specialized function for each value that can be stored in the corresponding value type. Here, for an integer, that might be 2 to the power of 64 functions. Whether you consider this efficient is up to you.
They are indeed similar and someone (Oscar) has proposed something similar before.
The main issue though is on the “little tweaking” part. You can certainly implement something to do that in dispatch but it requires much more than “little tweaking” to make it fast.
In general, we implement features in local scope (i.e. not global scope) that can be optimized using the knowledge that the compiler can know. In general this is the type and not the value so the most important optimization we do in julia is to statically decide the method to call based on type info (and this includes inlining). For pattern matching, you need to use the value in additional to the type. In additional to express it in the method table, which is not possible now since they can only hold types, in order to have any hope of running this fast, you have to be able to identify the patterns that matters and compute an (reasonably) optimized conditional statement that do the matching at runtime.
I’m not saying it’s impossible. It almost certainly is but is absolutely not “little”. Given that such features can be implemented quite easily already we are unlikely going to add it to be part of dispatch unless someone can donate a nice implementation that can be easily optimized and run fast.
Also note that the pattern matching this way is almost certainly not going to be as expressive as conditions since that’ll make the dispatch undecidable and it’ll make every other dispatch slow, something we absolutely don’t want.