From 0b4166fc180939874a61884aa76d2dfe53658da4 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Sun, 22 Feb 2015 21:10:12 +0800 Subject: +p8 --- p8.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 p8.hs diff --git a/p8.hs b/p8.hs new file mode 100644 index 0000000..219bc93 --- /dev/null +++ b/p8.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) -- cgit v1.2.3-70-g09d2