From a9ee47b61558efe09aee23f5671aabd0c3747e8a Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Tue, 17 Mar 2015 11:05:29 +0800 Subject: p -> h --- h8.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 h8.hs (limited to 'h8.hs') 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) -- cgit v1.2.3-70-g09d2