[Haskell-beginners] Re: strange take result--explanation?
Francesco Bochicchio
bieffe62 at gmail.com
Thu Mar 12 05:02:28 EDT 2009
2009/3/12 7stud <bbxx789_05ss at yahoo.com>
> 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?
>
>
>
I think because take -1 [1,2,3] is parsed as (take - 1 ) [1,2,3] or
something like that.
If you look to the error message, and translate the haskellese in plain
english, it says so.
"In the second argument of `(-)', namely `1 [1, 2, 3]' " :
so it looks like is looking for the two arguments of infix operator (-), the
first being 'take'.
But I don't understand because it says that 1 [1,2,3] is a single
argument...
"In the definition of `it': it = take - 1 [1, 2, 3]"
notice the blank between the minus sign and 1: even if you write -1, it
understands - 1.
So, ghc is trying to be helpful here :-)
Ciao
-----
FB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090312/596510f8/attachment.htm
More information about the Beginners
mailing list