Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Last active November 23, 2016 04:49
Show Gist options
  • Save chris-martin/612b9b680b736cced8372f187a6cfba7 to your computer and use it in GitHub Desktop.
Save chris-martin/612b9b680b736cced8372f187a6cfba7 to your computer and use it in GitHub Desktop.
#!/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