[jhc] Monad.ST

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


On Sun, 15 Nov 2009, Isaac Dupree wrote:

> Henning Thielemann wrote:
>> 
>> It compiles, but I have not tested any program that uses it. Even with 
>> simplest examples using storablevector it depends largely on fortune whether 
>> they run or crash. So no chance to make reliable statements about something 
>> more complex.
> 
> hmm, I looked at the code. I don't quite understand lazy ST, but I don't 
> think that version you made is correct.  The writes (and reads) really may 
> not be re-ordered based on which data is demanded when.

You are right. I only thought about newSTRef's for which the order is not 
important. Yes, we also have to assert that writes are in order and reads 
remain between adjacent writes. Once I solved a similar problem in the 'lazyio' 
package. I defined IO actions in a way, that triggering one action also 
requires to execute all previous actions. This should also work for ST but it 
is somehow overly strict. E.g.

   do a <- newSTRef 'a'
      b <- newSTRef 'b'
      writeSTRef a 'c'
      writeSTRef b 'd'

can be re-ordered to

   do b <- newSTRef 'b'
      writeSTRef b 'd'
      a <- newSTRef 'a'
      writeSTRef a 'c'


That is, maximum laziness would be achieved, if there would be a state-thread 
for every reference.


More information about the jhc mailing list