[Haskell-beginners] Question on (x:xs) form
Denis Albuquerque
denisalbuquerque at gmail.com
Mon Dec 23 18:55:35 UTC 2013
Hi Angus,
you need to put the parentheses around the pattern x:xs because the
application reverse' has priority over (:) , so the statement is the
same as
(reverse' x):xs = reverse' xs ++ [x]
and results the error.
-- Denis.
On Mon, Dec 23, 2013 at 12:57 PM, Angus Comber <anguscomber at gmail.com> wrote:
> Eg for a definition of reverse:
>
> reverse' :: [a] -> [a]
> reverse' [] = []
> reverse' (x:xs) = reverse' xs ++ [x]
>
> In the last line of the definition, x is an element in the list (the first
> element) and xs represents the remainder of the list.
>
> so if list was [1,2,3] then x is 1 and xs is [2,3]
>
> Why are the brackets required? And what do they signify?
>
> Eg reverse' x:xs = reverse' xs ++ [x] results in a parse error.
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
More information about the Beginners
mailing list