[Haskell-beginners] Question on (x:xs) form
Angus Comber
anguscomber at gmail.com
Mon Dec 23 14:57:35 UTC 2013
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131223/9eb534c6/attachment-0001.html>
More information about the Beginners
mailing list