[Haskell-cafe] Fixity declaration extension

AntC anthony_clayden at clear.net.nz
Tue Aug 14 02:49:39 CEST 2012

Ryan Ingram <ryani.spam <at> gmail.com> writes:

> When I was implementing a toy functional languages compiler I did away with 
precedence declarations by number and instead allowed the programmer to 
specify a partial order on declarations; this seems to be a much cleaner 
solution and avoids arbitrary precedences between otherwise unrelated 
operators defined in different modules.

I agree. I don't declare operators very often, and when I do I always struggle 
to remember which way round the precedence numbers go. I usually end up 
hunting for a Prelude operator that works the way I'm aiming for, then copy 
its definition. It would be much easier to declare the fixity of myop to be 
same as someotherop (which would presumably have to be already declared/fixed 
in an imported module).

[It's also slightly counterintuitive that the thing being defined comes last 
in an infix declaration, and that the stand-alone operator isn't in parens.]

    infixAs !! .$    -- fixing myop (.$) to be fixed as Preludeop (!!)

If you wanted to define precedence relative to some other operator(s), it 
might be clearer to give some model parsings (grabbing some syntax something 
like Ryan's):

    infix .$ (x ** y .$ z .$ w) ==> (x ** ((y .$  z) .$ w))
    -- === infixl 9 .$

OTOH, I think Евгений's proposal is getting too exotic. Do we really need such 
fine shades of binding? Will the reader remember how each operator binds 
relative to the others? Surely a case where explicit parens would be better.

(Anything else we can bikeshed about while we're at it?)


More information about the Haskell-Cafe mailing list