Created
December 1, 2017 17:52
-
-
Save sboehler/4424efe045c1831e885136e5a29067bd 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
module Main where | |
import Data.Monoid(Sum(..), getSum) | |
import Data.Char(digitToInt) | |
import System.Environment(getArgs) | |
main :: IO () | |
main = do | |
(arg:_) <- getArgs | |
let list = (Sum . digitToInt) <$> arg | |
print $ (getSum . mysum) list | |
mysum :: (Eq a, Monoid a) => [a] -> a | |
mysum l@(first:_) = | |
let | |
mysum' (x:y:rest') = (if x == y then x else mempty) `mappend` mysum' (y:rest') | |
mysum' [x] = if first == x then first else mempty | |
mysum' [] = mempty | |
in | |
mysum' l | |
mysum [] = mempty | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now just define (:^+^:) = mappend and o = mempty and it almost looks like proper addition again! :D