diff --git a/8.hs b/8.hs new file mode 100644 index 0000000..11b342d --- /dev/null +++ b/8.hs @@ -0,0 +1,10 @@ +-- Eliminate consecutive duplicates of list elements. + +myCompress :: (Eq a) => [a] -> [a] +myCompress [] = [] +myCompress [x] = [x] +myCompress (x:xs) + | x == (head xs) = myCompress ([x] ++ tail xs) + | otherwise = [x] ++ myCompress xs + +main = print (myCompress "AAAABBCDCEEEEA")