
13 Apr
2005
13 Apr
'05
12:30 p.m.
Hi all, I have a question about IO in a STM transaction. I want to make an atomic algorithm that does the following: 1. read an IORef 2. write some changes to the value you get from 1 3. save the IORef again Currently, I did this, roughly like this: doSomething :: IORef [s] -> s -> IO () doSomething ref s = atomically ( do { ss <- unsafeIOToSTM (readIORef s); do something with ss; unsafeIOToSTM (writeIORef s ss); return () } ) Since I read that STM uses a revertable log, I was wondering what happens with the IO actions, when a rerun on the atomic part is performed... I guess it will just redo them? Is this the unsafe-part of unsafeIOToSTM, or are there more caveats? Regards, Robert