I've seen mentioned that
ListT
is a classic example of a buggy monad transformer that doesn't satisfy the monad laws.
Can this be demonstrated by a simple example?
Edit: My idea with ListT []
is a bit wrong, I missed that the documentation requires the inner monad to be commutative. So, is ListT
buggy just in the sense that has this requirement, or is there another problem? (The examples at Haskell wiki all use ListT IO
and IO
is obviously not commutative.)
A simple example that shows how it fails the associativity law:
More examples (mostly using
IO
) and a solution how to fixListT
can be found at ListT done right.