Bug in Control.Monad.State

Yitzchak Gale gale at sefer.org
Mon Nov 21 14:40:37 EST 2005

In the following thread, I reported a problem I
was having with programs diverging when they use
infinite lists with StateT:


Roberto Zunino and Wolfgang Jeltsch pointed out
that this is a bug in Control.Monad.State: (>>=)
is lazy in State, but strict in StateT.

The source of the problem is that the pattern
match in the definition of (>>=) is inside a let
expression in State - so it is lazy - but inside a
do expression inside StateT - so it strict.

Roberto suggests a one-byte patch to fix this
problem: add '~' to make the pattern match in
StateT irrefutable.

(Note that this has already been done for the
MonadFix instance of StateT.)

The same fix should be applied to evalStateT and
execStateT. They are also stricter than their
non-transformer counterparts, for the same reason.


More information about the Libraries mailing list