[Haskell-cafe] mtl: Why there is "Monoid w" constraint in the definition of class MonadWriter?

Edward Z. Yang ezyang at MIT.EDU
Sun Dec 9 00:49:54 CET 2012


Excerpts from Holger Siegel's message of Sat Dec 08 15:27:38 -0800 2012:
> For deriving a monoid instance of w from monad  (Writer w), you will need
> function execWriter:: Writer w a -> w, but in case of a general instance of
> (MonadWriter w m) you would have to use function listen :: m a -> m (a, w)
> that will only provide you a value of type (m w), but not of type w. Therefore,
> I'm not yet convinced that every instance of (MonadWriter w m) gives rise
> to a monoid instance of w.

Definitely not. I need a way of running the monad, some way or another,
otherwise, it's like having the IO monad without a 'main' function :) But
you don't need very much to get there...

Edward



More information about the Haskell-Cafe mailing list