[Haskell-cafe] Desugaring of infix operators is (always?) the wrong way round

Brian Hulley brianh at metamilk.com
Tue Sep 25 16:03:17 EDT 2007

Jonathan Cast wrote:
> On Tue, 2007-09-25 at 19:18 +0100, Brian Hulley wrote:
>> Brian Hulley wrote:
>>> I'm wondering if anyone can shed light on the reason why
>>>    x # y
>>> gets desugared to
>>>   (#) x y
>>> and not
>>>   (#) y x
> Of course, this is all a consequence of the well-known failure of
> natural language: verbs come before their objects.  It is thus natural
> to write f(x), when in fact it is the object that should come first, not
> the function.  Switching to a (natural) language where (finite) verbs
> come at the end of sentences, where they belong, should fix this issue
> in time.  Doing the same in a functional language would be ideal as
> well, but might limit its use among those who speak inferior natural
> languages.
Thanks, I must look into using postfix notation. It's used in Forth and 
Postscript and I seem to dimly recall that there is a natural language 
somewhere that also uses it but I can't remember which one.

Not only would it solve the infix/prefix dilemma, but it would also be 
consistent with a sugar for an object oriented syntax for application:

    a b c f
    a .f(b, c)

 (Using a dot glued on its right and a left paren glued left to avoid 
ambiguity with unglued dot (function composition) and unglued left paren 

It's not so clear to me what the syntax for types should be in a postfix 
Also, a problem might be that it is not so easy to use the 
multiple-clause style of function definition eg compare:

    map _ [] = []
    map f (h : t) = f h : map f t


    [] f map = []
    (h : t) f map = h f : t f map

since the function name is no longer conveniently at the margin of 
whatever layout block we are in so extra efforts would need to be made 
to line them up, though this is a minor issue.

Thanks again,

More information about the Haskell-Cafe mailing list