Some special cases of method dispatch in Julia
bkamins.github.io
bkamins.github.io
The metaprogramming trick for defining a set of methods at once is useful, but I wish there were a more compiler-level solution to sorting out ambiguities or determining what's more "specialized".
These don't really color my view on multiple dispatch, however. I find it to be a really useful tool and I don't run into dispatch issues very frequently. If you're meticulous about your typing it's usually easy to avoid these pitfalls, but sometimes they still crop up.
https://github.com/aviatesk/JET.jl
It does catch method ambiguities like those shown in this blog post:
julia> using JET
julia> f(x, y::Int) = x + y
f (generic function with 2 methods)
julia> f(x::Int, y) = x - y
f (generic function with 2 methods)
julia> g(x, y) = f(x, y)
g (generic function with 1 method)
julia> @test_call g(1, 2)
JET-test failed at REPL[13]:1
Expression: #= REPL[13]:1 =# JET.@test_call g(1, 2)
═════ 1 possible error found ═════
┌ @ REPL[12]:1 Main.f(x, y)
│ no matching method found for call signature (Tuple{typeof(f), Int64, Int64}): Main.f(x::Int64, y::Int64)
└──────────────
ERROR: There was an error during testingi worked on a JVM programming language back in the day, and that damned feature screwed up everything: method resolution was obviously a pain, but it got involved in generics, class compatibility, it even ends up worming its way into bytecode, since methods names are really the name plus the fully qualified type name of every argument (even if there isn't any method overloading for a given method, just awful)
i wrote an old blog post on this:
https://guidewiredevelopment.wordpress.com/2009/05/22/i-am-h...
in conclusion: things should have unique names
Also, why does this complicate the parser? It looks like you're interfering some type information from later usage (the `foo( someVar )` example), so handling typing in the parser seems a bit strange.
As for the bytecode, it's not just methods: Fields likewise are identified by name and type and can be overloaded. I'm just happy that Java itself doesn't allow field overloading - I'm not the biggest fan of method overloading either.
just an awful feature that solves no problems that can't be better done with other features that, for whatever reason, just aren't as popular
I'm afraid that doesn't cut it in a modern programming context.
Sorry to hear that you failed to implement it back in the day, but that doesn't mean there's anything wrong with multiple dispatch in and of itself. It's just hard to get right. But when it works, it is without doubt the best paradigm for a language that I can think of.
BTW, optional arguments are not 'absent' in Julia, they are absolutely present, and are, in fact, implemented using multiple dispatch.
i'm shocked it's still up, tbh