This question shows an instance definition for (,) a b
, where a
is an instance of Monoid
.
However, I don\'t know how to write sim
We could write, for now synonyms works inappropriate for this case, so we use newtype:
newtype RevTuple b a = RevTuple { totuple :: (a , b) }
instance Monoid b => Monad (RevTuple b) where
return a = RevTuple (a,mempty)
(RevTuple (a,b)) >>= f =
let RevTuple (c,b1) = f a in RevTuple (c,b `mappend` b1)