[jhc] Monad.ST

Henning Thielemann jhc at henning-thielemann.de
Sun Nov 15 18:29:14 EST 2009


On Sun, 15 Nov 2009, Isaac Dupree wrote:

> Hopefully.  I'm afraid that might still be too much interleaving; consider 
> for example the definition of (>>) and (writeSTRef r a >> writeSTRef r b); 
> probably neither write will even happen, because the result () won't be 
> demanded!

If we evaluate
    runST (newSTRef x >>= \r -> writeSTRef r a >> writeSTRef r b)
   none of the writeSTRefs would be executed. But this would be correct, 
wouldn't it?

> or (writeSTRef r a >> readSTRef r)

If we evaluate
    runST (newSTRef x >>= \r -> writeSTRef r a >> readSTRef r)
  then readSTRef is triggered, because its result is requested and then 
because of the implementation of unsafeIOToST the previous actions are 
triggered. However, I see that I must implement strictToLazyST in terms of 
unsafeIOToST.


> (Also don't forget interleaving in instance Applicative Lazy.ST, if the 
> instances ultimately end up being involved)

indeed, I forgot that

see new patch


More information about the jhc mailing list