[Haskell-cafe] STM: "nested atomically" error

Johan Brinch brinchj at gmail.com
Tue Jan 24 16:50:21 CET 2012


On Fri, Jan 13, 2012 at 00:14, Johan Brinch <brinchj at gmail.com> wrote:
> Also, if the GHC IO system is using STM internally, what would be the
> correct way to say write a file? (where the IO action can be retried
> safely but have to run at least once, idempotent?). Please don't say
> "don't" :-)

I now believe that the correct answer is simply "don't". For anyone
who finds this thread later and wonder what happened:

I refactored the code to never use IO inside of STM transactions.
Instead, I'm now using the ErrorT IO STM to abort the transaction
early with an IO action that needs to be run before a retry. Aborting
with throwError doesn't rollback the transaction, which means one has
to be extremely careful as to what state is manipulated before
entering clean code (without any throwErrors).

This seems a lot more safe than doing IO inside the STM transactions
which has completely unpredictable (for me, at least) side effects.

-- 
Johan Brinch



More information about the Haskell-Cafe mailing list