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

Tomasz Zielonka tomasz.zielonka at gmail.com
Sat Feb 4 10:31:37 EST 2006


On Sat, Feb 04, 2006 at 02:52:20PM -0000, Brian Hulley wrote:
> Hi -
> In the Haskell98 report section 4.4.2 $ is specified as being right 
> associative. This means that f $ a0 a1 $ b0 b1 would parse as f (a0 a1 (b0 
> b1)) which seems rather strange to me. Surely it would be much more useful 
> if $ were defined as left associative so that it could be used to separate 
> the args to f?
> 
> Does anyone know why this strange associativity was chosen?

Probably it was anticipated that right associative version will
be more useful. You can use it to create a chain of transformations,
similar to a chain of composed functions:

    (f . g . h) x   =   f $ g $ h $ x

Example:

    map f $ group $ sort $ filter g $ l

But of course, left associative version can also be useful. Some
time ago I used a left associative version of the strict application
operator, which I named (!$).

Anyway, you can't always remove all parentheses. And why would you want
to? Everybody is used to them.

Best regards
Tomasz

-- 
I am searching for programmers who are good at least in
(Haskell || ML) && (Linux || FreeBSD || math)
for work in Warsaw, Poland


More information about the Haskell-Cafe mailing list