diff options
author | Joe Zhao <ztuowen@gmail.com> | 2015-02-22 21:10:12 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2015-02-22 21:10:12 +0800 |
commit | 0b4166fc180939874a61884aa76d2dfe53658da4 (patch) | |
tree | 0aab1080c1585a9c8e3a3bce4fb82218b003697f | |
parent | ae71c88c2e410a3c23387d9c393bf2d02a454bdf (diff) | |
download | h99-0b4166fc180939874a61884aa76d2dfe53658da4.tar.gz h99-0b4166fc180939874a61884aa76d2dfe53658da4.tar.bz2 h99-0b4166fc180939874a61884aa76d2dfe53658da4.zip |
+p8
-rw-r--r-- | p8.hs | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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) |