Version française
Home     About     Download     Resources     Contact us    
Browse thread
Custom operators in the revised syntax
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Loup Vaillant <loup.vaillant@g...>
Subject: Re: [Caml-list] Custom operators in the revised syntax
2007/5/10, Nicolas Pouillard <nicolas.pouillard@gmail.com>:
> Hello,
>
> Again this message is about the revised syntax and it's negative
> points or useless distances with the original one.
>
> Today it's about custom operators. In the original syntax everyone
> knows that's easy to define and use custom operators like ++, -->,
> >>>, +|, =?=, ... and as many as you want.
>
> To declare them in the original syntax one needs parens:
>
> let ( =?= ) x y = ...;;
>
> In the revised syntax one use a backslash:
>
> value \=?= x y = ...;
>
> Why not... but in the revised syntax these new operators are not
> automatically infix or prefix or postfix, you have to make your own
> syntax extension. In practice I found it too heavy, unless you already
> have a custom syntax extension local to the project or something like
> that.

I regret that a bit too. However, I can't tell I really miss it: I
find the default prefix syntax for function terse enough, so I don't
bother. The only useful usage I can think about is associative
operators, with which one can fold many arguments at once.

For example, the function composition :
(f (g (h (i x)))) becomes (f ° g ° h ° i) x
wich looks a bit better.


>
> However there is bad things with parens:
>
> - Not LL(1) when treating them in parsing
> - Spaces must be used for the `*' character to avoids starting comments.
>
> In fact when dealing them in the lexer that's ok.
> And the space issue is not too big.
>
> Concerning the fixity of these operators I've already changed it to
> have the same thing as the original syntax.

By the way, which are the fixity and associativity of custom operators
in the original syntax?


> Concerning the backslash, I want to restore the parens convention to
> declare them and then free the backslash character and make it
> available in the default lexer (useful for an ascii lambda for
> instance).

Err, I may not understand, but isn't "fun" terse enough? Or is it just
an idea from Haskell?

> As before, feel free to make comments on that (not really passionating) subject.

It should be : adding up "not really passionating" upgrades may lead
to a quiet revolution, eventually. :)

Regards,
Loup Vaillant