Last active
November 23, 2016 04:49
-
-
Save chris-martin/612b9b680b736cced8372f187a6cfba7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --resolver lts-7.8 --install-ghc runghc --package protolude | |
{-# LANGUAGE NoImplicitPrelude #-} | |
import Protolude | |
merge :: (Eq a, Semigroup a) => [a] -> [a] | |
merge (x:y:more) | x == y = (x <> y) : more | |
merge (x:xs) = x : merge xs | |
merge xs = xs | |
fix' :: (Eq a) => (a -> a) -> a -> a | |
fix' f x = if f x == x then x else fix' f (f x) | |
main :: IO () | |
main = putStrLn $ (show $ getSum <$> fix' merge (Sum <$> [1, 1, 1, 1, 3, 2, 2, 4, 3]) :: Text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment