Given a Maybe Int
, I tried to mappend
it to itself.
$let x = Just 55 :: Maybe Int $mappend x x <interactive>:126:1: No instance for (Monoid Int) arising from a use of `mappend' In the expression: mappend x x In an equation for `it': it = mappend x x
Looking at Maybe, I see:
Monoid a => Monoid (Maybe a)
Since Int does not implement Monoid
type-class, that explains why I can't use mappend
with Maybe Int
.
But, I remembered from LYAH that I can use Sum
:
ghci> let x = Sum 55 ghci> mappend x x Sum {getSum = 110}
But, why isn't Int
a Monoid?