diff --git a/9.hs b/9.hs new file mode 100644 index 0000000..957231e --- /dev/null +++ b/9.hs @@ -0,0 +1,12 @@ +-- Pack consecutive duplicates of list elements into sublists. If a list +-- contains repeated elements they should be placed in separate sublists. + +myPack :: (Eq a) => [a] -> [a] +myPack [] = [] +myPack [x] = [x] +myPack (x:xs) + | x == head xs = [x:myPack xs] + | + +main = print (myPack ['a', 'a', 'a', 'a', 'b', 'c', 'c', 'a', + 'a', 'd', 'e', 'e', 'e', 'e'])