[Haskell-cafe] monadplus as monoid, safe?

Nicolas Frisby nicolas.frisby at gmail.com
Wed Aug 30 15:56:29 EDT 2006


I'm using the following code in some of my projects:

> newtype MonadPlusAsMonoid a = MPM { unMPM :: a }
> instance MonadPlus m => Monoid (MonadPlusAsMonoid (m a)) where
>     mempty = MPM mzero
>     MPM l `mappend` MPM r = MPM (l `mplus` r)

Is there some sort of pitfall I'm not considering?

It seems fine to me, but I ask because I couldn't find this instance
in the darcs repo for the next base library package. I expected to
find it there because it has similar instances for numbers as monoids
(e.g. Sum and Product from Data.Monoid).

Thanks,
Nick


More information about the Haskell-Cafe mailing list