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: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] Custom operators in the revised syntax
On 5/10/07, Loup Vaillant <loup.vaillant@gmail.com> wrote:
> 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.

Exactly.

> > 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?

In fact the cool thing is that the rule is really simple, long
operators have the same associativity, fixity, priority as the well
known prefix of it.

Example:

+| is like + (infix, left assoc...)

<=> is like <

!* is like ! (prefix)

**/ is like ** (infix, right assoc)

Simple no?

> > 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?

I'm not talking about the revised syntax itself but about the reusable
camlp4 lexer, in case of using the camlp4 parsing system. If one want
to parse a language with lambdas as backslashs (like Haskell and
others one can do it).

I think also about operators like \/ for OR and /\ for AND.

> > 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. :)
:)

-- 
Nicolas Pouillard