Skip to content

Instantly share code, notes, and snippets.

@ckirkendall
Created September 30, 2012 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckirkendall/3808269 to your computer and use it in GitHub Desktop.
Save ckirkendall/3808269 to your computer and use it in GitHub Desktop.
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.
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