I guess I don’t see how this is awkward. It seems a very tidy mapping between syntactic sugar and underlying constructs.
All there ever is is extension_fun
. There isn’t any real fun
. If you want to write it that way yourself, go for it. extension (x: A) def fun(y: B) : C
is just because it looks nicer than def extension_fun(x: A)(y: B): C
. If we want it to be weirder, use $
instead of _
, and allow it to be spelled extension.fun
in Scala code. (Java has to use $
.)
So the compiler doesn’t get confused because there isn’t a separate thing to get confused by; you don’t need to prevent people from writing extension_foo
themselves because it’s exactly the same thing!
You import extension_fun
, always, and overriding works just like always. The only extra sugar is that when you see a.foo(b)
and a
doesn’t have a method foo
on it, check to see if extension_foo
is in scope and with the right type parameters.
There may be good reasons to have extension
be a hard keyword anyway, but I don’t see how the name-mangling is anything but simplifying and empowering.
(Aside: you can tell extension(f: Foo)
as a statement apart from extension(f: Foo) def
…you just need at least a LALR(2) parser. There’s the usual problem of inferring semicolons, but that’s no different from various other things like whether an extra (bippy)
on the next line is another parameter block, or an independent statement.)