[Haskell-cafe] Why is $ right associative instead of leftassociative?

Brian Hulley brianh at metamilk.com
Sat Feb 4 17:59:38 EST 2006

Jared Updike wrote:
>>         [a,b,c ; tail]      ===      a :: b :: c :: tail         --
>> where ::
> How is [a,b,c ; tail]   simpler, clearer or less typing than
> a:b:c:tail  ? I think that the commas and semicolons are easy to
> confuse.

It seems strange that you can write [a,b,c] with a nice list sugar but if 
you want to include a tail you have to switch to the infix notation using 
list cons. Prolog for example allows you to write [a,b,c|Tail] but neither 
Haskell nor ML allows this. In Haskell, | is used to introduce a list 
comprehension so I was just trying to find a replacement symbol for when you 
want the equivalent of the Prolog list sugar so that you wouldn't be forced 
to use infix notation.

All this was not to replace a:b:c:tail but was to replace a::b::c::tail so 
that : could be used for type annotations instead.

> While we're talking about the aesthetics of "::" and ":", I like how a
> line with a type annotation stands out strongly with "::", e.g.
> map :: (a -> b) -> [a] -> [b]
> Compare this to
> map : (a -> b) -> [a] -> [b]
> where the identifier looks more connected to the type.

This is no doubt because you are used to thinking of : as meaning list cons 
whereas I find the :: notation confusing for precisely the same reason.

> If you are designing your own langauge, you will of course have your
> own aesthetics and reasons for doing it your way. As for me, I started
> to design (in my head) the "perfect" language (for me), but the more I
> learned and used Haskell, the more I realized how carefully designed
> it was and how it was better for me to use my efforts to learn from
> Haskell (especially conceptually, since the syntax is so transparent
> and the ideas are so amazing) than to try to insert clever ideas to
> satisfy my own whims. Sure, there are always little things to nitpick,
> but on the whole, can you think of more succinct language with more
> power? (and less parentheses!) Plus, what other languages let you more
> easily add (infix) operators, etc. and change things to fit your whim,
> anyway (and still be strongly type!).

I've spent at least 3 years looking into various languages (Prolog, ML, 
Scheme, Lisp, Logo, Smalltalk, Mozart) before finally arriving at the 
pleasant shores of Haskell which has an incredibly well thought out and neat 
syntax not to mention a powerful type system. However there are some things 
that are just plain crazy, such as the existing layout rule which forces you 
to use a monospaced font when it would have been so simple to make a simpler 
layout rule using tabs that would result in grammatically robust code in the 
face of identifier renamings and editor font choices (as I've indicated on 
other threads), and the way constructors and field labels for different 
types are allowed to collide with each other in a module's namespace.

Feedback from this forum has been invaluable in helping me find a solution 
to this second problem and arrive at a good field selection syntax with 
semantics based on a compiler-defined global typeclass for each field label, 
although it has taken at least 3 months to discover this...

There are some funny things with the semantics I'm puzzled about - such as 
why Haskell is still based on Hindley Milner type inference with its 
troublesome monomorphism restrictions instead of intersection types which 
would allow everything to be mutually recursive with separate compilation of 
modules etc, but AFAIK no other language uses intersection types yet either, 
and Haskell is at least heading in the right direction with arbitrary rank 
forall polymorphism.

So I agree that Haskell is one of the best languages in existence at the 
moment all things considered, especially because it is a very good place to 
start when trying to develop the "perfect" language.

Regards, Brian. 

More information about the Haskell-Cafe mailing list