new keyword: infixlr?

Ian Lynagh igloo at earth.li
Sun Sep 12 10:34:43 EDT 2010


On Fri, Sep 10, 2010 at 11:14:53PM +0200, S. Doaitse Swierstra wrote:
> 
> On 10 sep 2010, at 20:13, Ian Lynagh wrote:
> 
> > On Fri, Sep 10, 2010 at 07:51:10PM +0200, S. Doaitse Swierstra wrote:
> >> 
> >> Currently Haskell has infix, infixl and infixr operators. I see a use for infixlr as well. This indicates that the implemtation may assume the operator to be associative, and thus has the freedom to "balance" an expression containing several operator occurrences.
> > 
> > Would it be restricted to use with operators with types that are (a -> a
> > -> a) (or more specific)?
> 
> This is what I would normally expect from an infix operator. 

I assume you mean "an associative operator", but even then it's not true
for (.).

And just because it is what you would expect, does not mean that people
will only use it in that way if the type system does not enforce it!

A detail is whether
    x ^^^ y = x ^ y
    infixlr ^^^
is rejected, or gives
    (^^^) :: (Num a, Integral a) => a -> a -> a

Although I guess if you require the compiler to give you the balanced
parse, there's no technical need to restrict the type of the operator as
it's deterministic.

Overall, my feeling is that this syntax feels very specialised and
fiddly, and would be better handled by a more general machanism similar
to GHC's RULE pragma, or by quasi-quotes or TH, or even by a domain
specific optimiser plugin which can see the result of inlining etc.


Thanks
Ian



More information about the Haskell-prime mailing list