
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?
Well, modifySTRef ref fun = do val <- readSTRef ref writeSTRef ref (fun val) (resp. 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 can't. It can ensure that the result is evaluated to a deeper level than required by the calling context when the function is entered, though.