haskell / haskell/transformers
fmap for Strict StateT is too lazy
- Dominant language
- Haskell
- Stars
- 5
- Forks
- 10
- Avg merge
- 2h 21m
- Merged PRs (30d)
- 1
Description
Following https://github.com/haskell/transformers/pull/122#issuecomment-5468883973 I was taking a look at the code out of curiosity and noticed that there is
https://github.com/haskell/transformers/blob/f1a27e41a348fed3697727a86adc2eb8030371f4/Control/Monad/Trans/State/Strict.hs#L191-L194
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
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with Control/Monad/Trans/State/Strict.hs at the fmap definition around lines 191–194 and run the reproducer in the issue. Compare its behavior with the stated Functor-Monad law, then inspect the surrounding StateT tests or add a focused regression test. Done means the fmap case is no longer lazier than the equivalent bind-and-return expression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100