summaryrefslogtreecommitdiff
path: root/H8.hs
diff options
context:
space:
mode:
Diffstat (limited to 'H8.hs')
-rw-r--r--H8.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/H8.hs b/H8.hs
new file mode 100644
index 0000000..219bc93
--- /dev/null
+++ b/H8.hs
@@ -0,0 +1,12 @@
+compress :: (Eq a) => [a] -> [a]
+compress = foldr elim []
+ where elim e [] = [e]
+ elim e ns
+ | e == head ns = ns
+ | otherwise = e:ns
+
+compress' xs = foldr f (const []) xs Nothing
+ where
+ f x r a@(Just q)
+ | x == q = r a
+ f x r _ = x : r (Just x)