Monoid instances for mtl

Henning Thielemann lemming at
Tue Jul 7 05:49:11 EDT 2009

On Mon, 6 Jul 2009, Stefan Holdermans wrote:

> Hi all,
> On a number of occasions I found myself declaring simple instances like
> instance Monoid a => Monoid (State s a) where
>   mzero   = return mzero
>   mappend = liftM2 mappend
> that make my life considerably easier. Would it be a good idea to add such 
> instances to the Monad Transformer Library?

... and to 'transformers'. However, in 'transformers' we had to define it 
for StateT, since (State s) is a synonym for (StateT s Identity). But I 
think this is a good idea anyway.

I also need this instance occasionally and had written a custom data type 
for this purpose:

Since it does only need Applicative functionality it can be defined for 
all other types in MTL.

More information about the Libraries mailing list