Strictness of modify in Control.Monad.State.Strict

Edward Kmett ekmett at
Fri Sep 28 06:13:57 CEST 2012

The strictness of Control.Monad.State.Strict has to do with the strictness
of the tuple constructor, not of the state per se. The dichotomy between
Lazy and Strict comes from the competing desires to fake products as
categorical products that don't introduce _|_'s of their own and the lifted
products we have in Haskell which do. The former leads you to the .Lazy
model, the latter leads you to the .Strict model. The former is nicer for
certain lazy knot tying tricks. The latter is easier to reason about when
you start throwing fmap _|_'s around.

However, a Strict State or Writer is not actually strict in the state or
log. This is admittedly a somewhat common misconception.

My concern is that such a combinator would exacerbate this confusion and
that it doesn't generalize. e.g. This trick doesn't generalize to
Strict.Writer, where you can `tell'`, but then you lose than on the next
bind after you lazily smash it into something that is probably just mempty.

I'm not against noting that put/modify is not the thing that we are
'Strict' in more carefully though.


On Thu, Sep 27, 2012 at 11:11 PM, Ben Gamari <bgamari.foss at> wrote:

> 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
> _______________________________________________
> Libraries mailing list
> Libraries at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list