I have this type:
newtype Mem s a = Mem { runMem :: s -> (a,s) }
and I have to create an instance of monoid for this type, but to do so I have to use the mempty and the mappend of the monoid a, regardless of what it may be. How would one go about doing that?
instance Monoid a => Monoid (Mem s a) where
mempty = --runMem with the mempty of a
f@(Mem aa) `mappend` g@(Mem aaa) = --runMem with mappend of a
f@(Mem s) `mappend` mempty = f
mempty `mappend` g@(Mem ss) = g
Thanks in advance
mempty
is simply themempty
ofa
and thes
that was passed in.mappend
can be defined as runningf
, theng
based on the results off
, then mappending the results: