Idempontent IO actions and unsafeSTMToIO

Benjamin Franksen benjamin.franksen at
Sat Aug 6 16:02:50 EDT 2005

On Saturday 06 August 2005 20:12, Robert van Herk wrote:
> Is it true to say that to perform idempotent IO actions inside a STM
> monad by using unsafeSTMToIO is safe? I mean something like:
> do ... -- some STM actions
>      unsafeSTMToIO a -- Here, a is an idempotent IO action
>      ... -- some other STM actions
> What I read from the various sources on the web is that unsafeSTMToIO
> is just unsafe in the sence that the IO actions may be performed
> multiple times. So I recon that, if the IO actions are idempotent,
> there would be no problem.
> Am I correct?

I think that idempotent actions could still cause problems. For 
instance, assume the action is 'remove file x', which is surely 
idempotent. Now, imagine the following STM code:

  doit <- readTVar v
  unsafeIOToSTM (do removeFile filename)
  if not doit then retry else return ()

Here, the file gets removed regardless of the value of the TVar 'v', 
although (presumably) it should be run only when 'v' contains 'True'.


More information about the Glasgow-haskell-users mailing list