No subject
Thu Jul 5 12:38:43 CEST 2012
(m1 >> m2) >> m3 === m1 >> (m2 >> m3)
Now, consider tell. We'd expect it to obey a law like this:
tell w1 >> tell w2 === tell (w1 <> w2)
Combine this with the monad associativity law:
(tell w1 >> tell w2) >> tell w3 === tell w1 >> (tell w2 >> tell w3)
And it's easy to see that '<>' must be associative in order for this law
to be upheld. Additionally, the existence of identities in monads means
that there must be a corresponding identity for the monoid.
So anything that is "writer-like" and also satisfies the monad laws...
is going to be a monoid.
Now, it's possible what GP is actually asking about is more a question of
encapsulation. Well, one answer is, "Well, just give the user specialized
functions which do the appropriate wrapping/unwrapping"; another answer is,
"if you let the user run a writer action and extract the resulting written
value, then he can always reverse engineer the monoid instance out of it".
Edward
More information about the Haskell-Cafe
mailing list