As Matt Bryant said, a specific compiler error involves using [xs] instead of xs .
You actually have a redundant pattern:
removeduplicate (x:z:[]) if z == x then [x] else (x:z:[])
This line may be deleted because a pattern of type x:y:[] already being processed
removeduplicate (x:y:xs) | x == y = x:(removeduplicate xs) | otherwise = x:y:(removeduplicate xs)
Since xs can be an empty list, and removeduplicate [] allowed in [] .
Keep in mind that the code you provided only removes up to two consecutive repeating elements. With three consecutive duplicates, two identical elements will be inserted into the result, which is probably not what you want.
A more complete function might look something like this:
removeduplicate [] = [] removeduplicate (x:xs) = x:(removeduplicate $ dropWhile (== x) xs)
source share