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
andmappend
and the type system will figure out whichmempty
you meant. – Julia Pathmempty = Mem (\s -> (mempty, s))
. – Julia Path