Following #122 (comment) I was taking a look at the code out of curiosity and noticed that there is
|
instance (Functor m) => Functor (StateT s m) where |
|
fmap f m = StateT $ \ s -> |
|
fmap (\ (a, s') -> (f a, s')) $ runStateT m s |
|
{-# INLINE fmap #-} |
This is too lazy and doesn't obey the Functor-Monad law that fmap f m = m >>= return . f
>>> import Control.Monad.Trans.State.Strict
>>> runStateT (fmap (const ()) (StateT (\_ -> pure undefined))) () *> print "ok"
"ok"
>>> runStateT (StateT (\_ -> pure undefined) >>= pure . const ()) () *> print "ok"
*** Exception: Prelude.undefined
Following #122 (comment) I was taking a look at the code out of curiosity and noticed that there is
transformers/Control/Monad/Trans/State/Strict.hs
Lines 191 to 194 in f1a27e4
This is too lazy and doesn't obey the Functor-Monad law that
fmap f m = m >>= return . f