[Haskell-beginners] Re: strange take result--explanation?

Brent Yorgey byorgey at seas.upenn.edu
Thu Mar 12 08:45:08 EDT 2009


On Thu, Mar 12, 2009 at 08:14:41AM +0000, 7stud wrote:
> 7stud <bbxx789_05ss <at> yahoo.com> 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


More information about the Beginners mailing list