sections of noncommutative operators

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; it's probably my lisp background that tripped me up. But is there any way this could be made less confusing? Do any of the online tutorials warn against this sort of mistake, and I just missed it? Mike

"Michael Shulman"
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@cl.cam.ac.uk http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html (updated 2006-09-07)

On Sat, 2006-09-09 at 11:17 +0100, Jón Fairbairn wrote: . . .
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?
For Scheme, R5RS, Section 6.2.5 specifies that "<" and ">" take two or more arguments, and PLT Scheme raises an exception on "(< 0)". For Common Lisp, CLtL2 specifies for =, /=, <. >, <=, >= that "These functions take one or more arguments" (p. 293). "(< x1 ...)" is true when the arguments form a monotonically increasing sequence, and clearly a singleton sequence is monotonic. In the CLISP implementation of Common Lisp "(< 0)" returns "T". BTW there is no "lessp" in CL. As you noted, CL and Scheme do not support currying. However, SRFI 16 (Scheme Request for Implementation, a quasi-standard mechanism for introducing extension libraries into Scheme) provides a "Notation for Specializing Parameters without Currying" as a syntactic sugar for nested lambdas. -- Bill Wood

No, lisp doesn't have currying, but of course I knew that Haskell
does. I think my thought processes went something like this: I want
to partially apply "<", but < is an infix operator in Haskell, so
first I have to convert it to the function (<) written with prefix
notation and then partially apply it. That led me to ((<) 0), and
then I mistyped (< 0), probably since in lisp < is already a function
written with prefix notation. I guess to someone not coming from
lisp, (< 0) means "less than zero" and not "the function < with 0
passed as its first argument". I guess I'm just unlucky enough to get
confused by something that other people find straightforward. (-:
On 09 Sep 2006 11:17:52 +0100, Jón Fairbairn
Right about the start of the design of Haskell, I proposed the rule "parentheses should only be used for grouping".
I think I would have liked that rule. Are parentheses currently used for anything else besides grouping and sections? Mike

Michael Shulman wrote:
On 09 Sep 2006 11:17:52 +0100, Jón Fairbairn
wrote: Right about the start of the design of Haskell, I proposed the rule "parentheses should only be used for grouping".
I think I would have liked that rule. Are parentheses currently used for anything else besides grouping and sections?
Yes: tuples, contexts, set of classes to derive from in a deriving clause, module export list, import directives. Regards, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com

On 9/9/06, Brian Hulley
Yes: tuples, contexts, set of classes to derive from in a deriving clause, module export list, import directives.
I guess I thought of most of those as a sort of grouping, without really thinking about it. But I suppose you are right that they are actually different. Mike
participants (4)
-
Bill Wood
-
Brian Hulley
-
Jón Fairbairn
-
Michael Shulman