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

Brian Hulley brianh at metamilk.com
Tue Sep 25 18:03:09 EDT 2007

Dan Piponi wrote:
> On 9/25/07, Brian Hulley <brianh at metamilk.com> wrote:
>> ..I seem to dimly recall that there is a natural language
>> somewhere that also uses it but I can't remember which one.
> Every permutation of [S,V,O] appears in 'nature':
> http://en.wikipedia.org/wiki/Word_order.

Thanks for the link - I see [Subject, Object, Verb] is actually the most 
common word order.
>> Also, a problem might be that it is not so easy to use the 
>> multiple-clause style of function definition 
> I disagree, it's easier with postfix functions. With prefix functions,
> to get line-up you insert space in the middle of the line. With
> postfix notation you would often insert space at the beginning of a
> line, a much easier place to insert text, because there is a
> keystroke, in most text editors, to take you to the beginning of a
> line.

I don't understand what you mean. For example, with the prefix 
definition of a function with multiple clauses, the function name at the 
start of each clause is already lined up since it must appear at the 
margin of the current layout block (especially if you follow the simple 
rule of always following a layout starter token by a newline rather than 
starting a new multi-line layout block in the middle of a line), whereas 
with the postfix notation you'd need to manually line up the function 
names if you wanted the same neat look.

>> It's not so clear to me what the syntax for types should be in a postfix language.
> Postfix, of course! So you'd write
> data a Tree = Leaf | a a Tree

Sorry I meant what should the syntax of type declarations for functions 
be? For example, with prefix map (writing lists without sugar for 
clarity) we have:

    map :: (a -> b) -> List a -> List b
    map _ Empty = Empty
    map f (PushF h t) = PushF (f h) (map f t)

The occurrence of "map" in the type decl lines up with the 2 occurrences 
of "map" in the clauses, and the types of the arguments are in the same 
order in the type as in the patterns in the clauses.

A postfix version could be:

    map :: (a -> b) -> a List -> b List
    Empty _ map = Empty
    (h t PushF) f map = (h f) (t f map) PushF

but now the occurrences of "map" no longer line up and the argument 
order is reversed between the type and the value syntax.

Of course the problem disappears if you just discard multiple clause 
syntax and use:

   (list :: a List) (f :: a -> b) map :: b List =
        case list of
            Empty -> Empty
            h t PushF -> (h f) (t f map) PushF

> Confusingly, ocaml does something like this, with postfix notation for
> types and prefix notation for function application.

I've never understood why {Oca, S}ML's creators decided to make life so 
difficult and confusing by introducing an arbitrary reversal between 
type and value syntax. ;-)


More information about the Haskell-Cafe mailing list