[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:45:54 CET 2012
> First of all, I don't see why two tells should be equivalent to one
> tell. Imagine a MonadWriter that additionally records the number of
> times 'tell' has been called. (You might argue that your last equation
> should be a MonadWriter class law, but that's a different story — we're
> talking about the Monad laws here.)
Yes, I think I would argue that my equation should be a MonadWriter class
law, and if you don't grant me that, I don't have a leg to stand on.
> Second, even *if* the above holds (two tells are equivalent to one
> tell), then there is *some* function f such that
>
> tell w1 >> tell w2 == tell (f w1 w2)
>
> It isn't necessary that f coincides with mappend, or even that the type
> w is declared as a Monoid at all. The only thing we can tell from the
> Monad laws is that that function f should be associative.
Well, the function is associative: that's half of the way there to
a monoid; all you need is the identity! But we have those too:
whatever the value of the execWriter (return ()) is...
Cheers,
Edward
More information about the Haskell-Cafe
mailing list