I just tried to write a function that removes two subsequent identical entries of a list. (As soon as there are two identical entries in the list, they should be removed.) I came up with following recursive function, which works exactly as expected. It relies on pattern matching:
f :: Eq a => [a] -> [a]
f(a:b:xs)|a==b = f xs
|otherwise = a : f (b:xs)
f x=x -- if the list has less than two entries
Now I though we could rewrite the second case as f=id
, but for the code
f :: Eq a => [a] -> [a]
f(a:b:xs)|a==b = f xs
|otherwise = a : f (b:xs)
f = id
I get following error, which I do not understand:
\path\to\my\program.hs:1:1:
Equations for `f' have different numbers of arguments
\path\to\my\program.hs:
(1,1)-(2,34)
\path\to\my\program.hs:
3:1-6
Failed, modules loaded: none.
As I see it both have the exact same number of arguments (one), but GHC does not seem to agree, can anyone explain what I did wrong?