Haskell infix syntax
spir
denis.spir at gmail.com
Mon Mar 7 05:44:27 PST 2011
On 03/07/2011 02:05 PM, Jacob Carlborg wrote:
> You could implement operator overloading without any special cases/support in
> the language, like Scala does. In Scala
>
> 3 + 4
>
> Is syntax sugar for:
>
> 3.+(4)
>
> It's possible because of the following three reasons:
>
> * Everything is an object
> * Method names can contain other characters than A-Za-z_
> * The infix syntax discussed in this thread
>
> Implementing operator overloading like this also allows you to add new
> operators and not just overloading existing ones.
We could give a standard name to each character in an allowed class, so that
x !%# y
maps to
x.opBangPercentHash(y);
;-)
Another solution is to specify operators in method defs:
X opBangPercentHash as "!%#" (X y) {...}
Or even use them directly there:
X !%# (X y) {...}
possibly with an annotation to warn the parser:
@operator X !%# (X y) {...}
In any case, /this/ is not a big deal to manage in symbol tables, since an
operator is just a string like (any other) name. The big deal is to map such
features to builtin types, I guess (which are not object types).
Denis
--
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d
mailing list