Created
September 30, 2012 19:46
-
-
Save ckirkendall/3808269 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
Illegal instance declaration for `Monoid [Char]' | |
(All instance types must be of the form (T a1 ... an) | |
where a1 ... an are *distinct type variables*, | |
and each type variable appears at most once in the instance head. | |
Use -XFlexibleInstances if you want to disable this.) | |
In the instance declaration for `Monoid [Char]' | |
Failed, modules loaded: none. |
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
class Monoid a where | |
append :: a -> a -> a | |
identity :: a | |
foldLeft :: [a] -> b -> (b -> a -> b) -> b | |
foldLeft [] x f = x | |
foldLeft (h:l) x f = foldLeft l (f x h) f | |
instance Monoid Int where | |
append x y = x + y | |
identity = 0 | |
instance Monoid [Char] where | |
append x y = x ++ y | |
identity = "" | |
mysum :: (Monoid a) => [a] -> a | |
mysum l = foldLeft l identity append | |
main :: IO () | |
main = do | |
let x = [1::Int, 2, 3] | |
y = ["1", "2", "3"] | |
print (mysum x) | |
print (mysum y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment