
12 Mar
2009
12 Mar
'09
8:45 a.m.
On Thu, Mar 12, 2009 at 08:14:41AM +0000, 7stud wrote:
7stud
writes: Why does
take (0 - 1) [1, 2, 3]
produce a result but not
take -1 [1, 2, 3]
? Thanks
Well, immediately after I hit the submit button, I thought I'd try this:
*Main> take (-1) [1, 2, 3] []
So why are the parentheses needed there?
Negative numbers are a rather ugly corner of the Haskell lexical specification. Indeed, without the parentheses, Haskell thinks you are trying to use subtraction. Just always use parentheses around negative numbers and you'll be fine. =) -Brent