Strictness of modify in Control.Monad.State.Strict
Ben Gamari
bgamari.foss at gmail.com
Fri Sep 28 05:11:13 CEST 2012
Is there a reason there is no `modify` operation in
Control.Monad.State.Strict (and the transformers analogue) which is
truly strict in the state? That is,
modify' :: Monad m => (a -> a) -> StateM a m ()
modify' f = get >>= (\x -> put $! f x)
While this is admittedly not a difficult piece of code to write, even
the suggestion in the documentation that `modify` isn't as strict as one
might think would likely save many man-hours of debugging (especially
for those who are less familiar with the language, for whom, speaking
from experience, strictness issues can pose a major hurdle to adoption)
In general it would be nice if the notion of strictness were better
addressed in the major libraries' documentation. It's a nuanced
issue which is not fully captured by a ".Lazy" or ".Strict" in the
module name.
Just a thought.
Thanks,
- Ben
More information about the Libraries
mailing list