[Haskell-cafe] ST not strict enough?

Daniel Fischer daniel.is.fischer at googlemail.com
Fri Nov 18 14:17:38 CET 2011

On Friday 18 November 2011, 13:05:06, Yves Parès wrote:
> ...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 ref fun = do
    val <- readSTRef ref
    writeSTRef ref  (fun val)

modifySTRef ref f = writeSTRef ref . f =<< readSTRef ref
as it's actually written in Data.STRef).

What's written to ref is the thunk (fun val), meaning, "when the value is 
demanded, evaluate fun applied to the argument val".

So, no, the function is not entered before the result is demanded, hence it 
It can ensure that the result is evaluated to a deeper level than required 
by the calling context when the function is entered, though.

More information about the Haskell-Cafe mailing list