From 4c0dc66a155477ceabf4f8b6564dfe42abfc2ad8 Mon Sep 17 00:00:00 2001 From: Arcania0311 Date: Thu, 12 Jun 2014 14:17:48 +0200 Subject: [PATCH] 9 is not yet finished. --- 9.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 9.hs 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'])