[Haskell-beginners] ($) operator

Dave Bayer bayer at cpw.math.columbia.edu
Sun Jan 25 09:13:41 EST 2009

2009/1/24 John Hartnup <john.hartnup at gmail.com>:

> But is that it's only purpose? To placate the LISP haters by removing
> parentheses?

On Jan 25, 2009, at 12:25 AM, David Morse wrote:

> They definitely dropped the ball on introducing '$'. I think you just
> hit the seam between two of the authors, and it fell through the
> cracks.

Haskell isn't Cobol, but in comparison with the lambda calculus, it  
flows a bit better like a natural language. '$' helps with this.

For example, in the line

> 	mempty = en $ en []

...one clearly doesn't need to use $, parenthesizing (en []) has the  
same meaning. However, reading left-to-right, the $ coaxes one into  
dropping top-down into a new view of the line, partially abstracting  
out or forgetting what came before, without having to maintain a  
mental stack and brace oneself for the closing ).

I've read books on numeracy and vision, that present the same  
conclusion: As our brain evolved new systems for seeing or counting,  
the old systems didn't get thrown out, they got buried by the new  
layers, but they're still wired in. Part of our reaction to a line of  
lisp that ends in seven )))))) is no different than a pigeon or a  
horse seeing the same number of objects; we're not sure. Then for us a  
new linguistic layer kicks in, "I can see two groups of three, that's  
even" and we rise above the animals, but our single conscious core got  
hijacked to sort this out.

People take the ergonomics of cockpit design very seriously, to reduce  
the cognitive load on pilots in emergencies. On Apollo 13, they nearly  
blew it by flipping a switch the wrong way. I fly a lot, so I'm very  
grateful that the "purists" that gravitate to math and computer  
science aren't instead in ergonomic design.

I actually love lisp, or more precisely Scheme. I came back to Haskell  
for strong typing and class abstractions; Haskell more directly  
supports making a theory about what one is coding. In order to use  
Scheme, I had to defang it of its parentheses. I didn't believe that  
any of the web proposals for this saw actual use, so I rolled my own  
preprocessor, using indentation to indicate outline structure, and  
using '|' roughly as Haskell uses '$'. There are other issues one  
inevitably faces, e.g. missing starts to outline levels, but I came to  
love '$' as Haskell uses it.

Some people develop a point-free style in Haskell, e.g.

> 	blah foo . blah . blah foo foo . blah

and different people write code that piles up uses of '$' e.g.

> 	blah foo $ blah $ blah foo foo $ blah

With decent syntax coloring the second line can be given as light a  
touch as the first.

Ultimately, '$' helps mitigate a left / right tension in Haskell that  
exists in all languages, and in algebra itself.

In algebra, "f g" can mean either "f then g" or "g then f". It means  
"g then f" in any situation crippled by the ancestry of the function  
composition "f(g(x))", and it means "f then g" any time one has the  
free choice of easier ergonomics in a culture that reads left to right.

Quick, ten times, work out out the permutation cycle product

> 	(1 2 3) (2 3 4 5) (3 4 5 6) (4 5 6 2) (5 6 1 2) (1 2 3) (2 3 4 5)  
> (3 4 5 6) (4 5 6 2) (5 6 1 2)

under each assumption for the order of operations. One wraps around  
through parentheses either way, but using the "f then g" convention,  
all other scanning is consistently left to right, not flitting back  
and forth like a deranged water bug.

Now try composing a complex set of type signatures for Haskell  
functions. Do you feel like a deranged water bug? The arrows go the  
wrong way, don't they! You'd be playing a nice game of dominoes,  
canceling off neighbors and so forth, if the arrows went the other way.

So Haskell doesn't have its left / right tension completely worked  
out, but I'd say '$' isn't part of the problem, it's part of the  

More information about the Beginners mailing list