[Haskell-cafe] ST not strict enough?

Ryan Ingram ryani.spam at gmail.com
Tue Nov 22 02:20:28 CET 2011

On Fri, Nov 18, 2011 at 4:05 AM, Yves Parès <limestrael at gmail.com> wrote:

> (Sorry for the double mail)
> ...so there is no way to do that inside the function passed to modifySTRef?
> In other words, there is no way to ensure *inside* a function that its
> result will be evaluated strictly?

modifySTRef looks like this (sugared up a bit):

modifySTRef r f = do
    x <- readSTRef r
    writeSTRef r (f x)

Note that this writes the *thunk* (f x) to the STRef, and there is
absolutely nothing you can do about it.  "f" isn't demanded by this
function, let alone "f x".

You can implement your own strict modifySTRef' easily though, as other
people in this thread have shown.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111121/1413cbe4/attachment-0001.htm>

More information about the Haskell-Cafe mailing list