[Haskell-cafe] Stronger STM primitives needed? Or am I just doing it wrong?

Sterling Clover s.clover at gmail.com
Wed Apr 23 18:37:17 EDT 2008

>> -- non-primitive retryUntil:
>> retryUntil v p = do
>>    x <- readVar v
>>    unless (p x) retry
>> broken2 = atomically $ do
>>    (v1, v2) <- expensive_computation :: STM (TVar Int, TVar Int)
>>    retryUntil v1 (> 50)
>>    x <- expensive_computation2 :: STM Int
>>    retryUntil v2 (> x)
> If v1 succeeds and v2 fails, then v1 changes to some other value > 50,
> I am sure that the STM runtime as it stands now will re-run
> expensive_computation2.

But expensive_computation2 is in STM. This means that it *should* be  
rerun, no? Between the first run and the retry, the result of  
expensive_computation2 may well have changed. If it doesn't get  
rerun, then we may have violated another transactional integrity  
constraint unknowingly. STM transactions should either happen once,  
or not at all. But if expensive_computation2 is not rerun, there's  
the possibility of "spooky action at a distance" effects, as I  
understand it? A more specific solution would be to build a memo- 
table (either with a CAF or via either TVars or MVars) structure into  
expensive_computation2 such that if it is rerun with the same TVar  
input, its work doesn't need to be recomputed.


More information about the Haskell-Cafe mailing list