[Haskell-cafe] monoids and monads

John Lato jwlato at gmail.com
Tue Jul 27 05:47:26 EDT 2010

On Tue, Jul 27, 2010 at 8:32 AM, Henning Thielemann
<schlepptop at henning-thielemann.de> wrote:
> John Lato schrieb:
>> Hello,
>> I was wondering today, is this generally true?
>> instance (Monad m, Monoid a) => Monoid (m a) where
>>   mempty = return mempty
>>   mappend = liftM2 mappend
>> I know it isn't a good idea to use this instance, but assuming that
>> the instance head does what I mean, is it valid?  Or more generally is
>> it true for applicative functors as well?  I think it works for a few
>> tricky monads, but that's not any sort of proof.  I don't even know
>> how to express what would need to be proven here.
> I translate 'valid' and 'true' to "Is 'm a' a Monoid, given that 'm' is
> a Monad and 'a' is a Monoid?" If this is the question then we have to
> show the Monoid laws for (m a), namely

Thanks very much, this is what I was unable to express properly (hence
the informal description).

> left identity:   forall x. mappend mempty x = x
> right identity:  forall x. mappend x mempty = x
> associativity:
>   forall x y z.
>      (x `mappend` y) `mappend` z = x `mappend` (y `mappend` z)

So the task now is to prove that these laws hold, given the instance I
defined above, the monoid laws for 'a', and the monad laws for 'm'.
Or alternatively using applicative laws for 'm' for the more general
case.  I'll see how I get on from here then.


More information about the Haskell-Cafe mailing list