[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Extensible infix operators
- From: John Hind <john.hind@...>
- Date: Thu, 30 Nov 2006 18:44:38 +0000
Thanks - I clearly should look into this stuff, it looks really powerful.
However at a formal (rather than implementation) level would using an
unadorned token really cause ambiguities? It would be neater without a
special syntax and it should surely be possible to disambiguate this
given that the compiler knows that the token refers to a function (or
not). I'd kind of like to add "mathematical" convention multiplication
too i.e. a b is interpreted as a * b.
On 11/29/06, *Fabien* <fleutot+lua@gmail.com
<mailto:fleutot+lua@gmail.com>> wrote:
On 11/29/06, *John Hind* <john.hind@zen.co.uk
<mailto:john.hind@zen.co.uk>> wrote:
I'd like to be able to offer extensible infix operators so
you'd be able to write something like:
c = a func b
This would be evaluated as:
c = func(a, b)
I really like Haskell's solution, which allows to put arbitrary
functions in infix position, if you put it between backquotes, as
in: "a `func` b". Unfortunately, it clashes with my syntax for
algebraic datatypes
On second though, it doesn't clash. It's actually a straightforward
extension to implement:
-{ mlp.expr.add_postfix_sequence{ "`", mlp.id <http://mlp.id>, "`",
mlp.expr,
prec = 30, assoc = "left", builder = |x| `Call{ x[2], x[1], x[3] } } }
But there's still an issue, it relies on a partially unimplemented
feature of the grammar generator: precedence and associativity hints
aren't handled properly by postfix sequences, so the extension above
will behave as if it had infinite precedence and were right associative.
But that will be fixed eventually, so this infix call extension will work.