[Haskell-cafe] Re: sections of noncommutative operators

Jón Fairbairn jon.fairbairn at cl.cam.ac.uk
Sat Sep 9 06:17:52 EDT 2006

"Michael Shulman" <viritrilbia at gmail.com> writes:

> A propos of sections of subtraction, and thence to sections of other
> noncommutative operators, as a Haskell newbie I was surprised to
> discover (the hard way!) that
> (< 0)
> and
> ((<) 0)
> mean different things.  I had typed (< 0) when I meant to type ((<)
> 0).  No compiler errors, of course, and I had a devil of a time
> finding that bug.  My initial reaction was that (< 0) should be an
> error and you should have to write ((>) 0); now I realize that the
> section notation is more fundamental, since (<) itself is actually a
> "double section".  And of course I should have written (> 0) anyway;

Well, this is the first time I've noticed anyone mention it!
If you appreciate sections, you read (< 0) as "less than
zero", and the meaning is clear.  I don't think it takes
much in the way of mental gymnastics to do that, since you
just read the tokens in order.

> it's probably my lisp background that tripped me up.

I should think so. But does lisp have currying these days? 
(lessp 0 1) ==> T
but (lessp 0) would be an error, wouldn't it?

> But is there any way this could be made less confusing?

Right about the start of the design of Haskell, I proposed
the rule "parentheses should only be used for grouping". If
we had adopted that, you wouldn't have been confused by
sections, because sections would have had to use a different
syntax.  However, while I was reluctant to lose the rule,
sections in their present form do have a great deal to be
said for them.

Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2006-09-07)

More information about the Haskell-Cafe mailing list