[Haskell-cafe] A question about "monad laws"
Miguel Mitrofanov
miguelimo38 at yandex.ru
Mon Feb 11 12:46:25 EST 2008
> (x >>= f) >>= g == x >>= (\v -> f v >>= g)
>
> However, this seems to me a kind of mathematical identity. If it is
> mathematical identity, a programmer need not care about this law to
> implement a monad. Can anyone give me an example implementation of
> monad that violate this law ?
It's well known that "ListT m" monad violates this law in general
(though it satisfies it for some particular monads m). For example,
Prelude Control.Monad.List> runListT ((ListT [[(),()]] >> ListT [[()],
[()]]) >> ListT [[1],[2]])
[[1,1],[1,2],[2,1],[2,2],[1,1],[1,2],[2,1],[2,2],[1,1],[1,2],[2,1],
[2,2],[1,1],[1,2],[2,1],[2,2]]
Prelude Control.Monad.List> runListT (ListT [[(),()]] >> (ListT [[()],
[()]] >> ListT [[1],[2]]))
[[1,1],[1,2],[1,1],[1,2],[2,1],[2,2],[2,1],[2,2],[1,1],[1,2],[1,1],
[1,2],[2,1],[2,2],[2,1],[2,2]]
More information about the Haskell-Cafe
mailing list