Hello. I am learning Haskell and I am currently writning Haskell code that (description blow)
Write a function that eliminates consecutive duplicates of list elements.
compress :: Eq a => [a] → [a]
If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should not be changed.
For example:
compress [2,2,2,1,2,2,3,3,3]
[2,1,2,3]
Then my code is
remdups :: Eq a => [a] → [a]
remdups =
remdups =
remdups (x1:x2:xs)
| x1==x2 = remdups (x2:xs)
| otherwise = x1:remdups (x2:xs)
main = putStrLn(show remdups[2,2,2,1,2,2,3,3,3])
I visited some websites that explain simmilar problem and I tryied to use some code from the websites, but did not work.
Could anyone tell and teach me what is wrong with mi code and fix my code?
Thank you for your helping in advance.