8 Dec 2012 19:59
mtl: Why there is "Monoid w" constraint in the definition of class MonadWriter?
Petr P <petr.mvd <at> gmail.com>
2012-12-08 18:59:25 GMT
2012-12-08 18:59:25 GMT
The class is defined as
> class (Monoid w, Monad m) => MonadWriter w m | m -> w where
> ...
What is the reason for the Monoid constrait? It seems superfluous to me. I recompiled the whole package without it, with no problems.
Of course, the Monoid constraint is necessary for most _instances_, like in
> instance (Monoid w, Monad m) => MonadWriter w (Lazy.WriterT w m) where
> ...
but this is a different thing - it depends on how the particular instance is implemented.
I encountered the problem when I needed to define an instance where the monoidal structure is fixed (Last) and I didn't want to expose it to the user. I wanted to spare the user of of having to write Last/getLast everywhere. (I have an instance of MonadWriter independent of WriterT, its 'tell' saves values to a MVar. Functions 'listen' and 'pass' create a new temporary MVar. I can post the detail, if anybody is interested.)
Would anything break by removing the constraint? I think the type class would get a bit more general this way.
Thanks for help,
Petr Pudlak
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe <at> haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RSS Feed