Proposal: Add throwSTM and generalize catchSTM

Bas van Dijk v.dijk.bas at
Sun Sep 26 11:24:55 EDT 2010

Dear all,

Currently the only way to throw an exception in an STM transaction is
via throw. The IO monad has the throwIO function which guarantees
ordering with respect to other IO actions. It would be nice to have a
similar function for the STM monad:

throwSTM :: Exception e => e -> STM a

I propose adding this to Control.Monad.STM.

Additionally I propose to generalize:

catchSTM :: STM a -> (SomeException -> STM a) -> STM a


catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a

to make it consistent with the IO catch function:

catch :: Exception e => IO a -> e -> IO a -> IO a

and allow packages like exception-monads-fd/tf to define an instance
MonadException STM.

I don't have a patch because I think these changes also require
modifying/extending the rts which I don't feel comfortable with doing
right now.

Discussion deadline: Three weeks, until Sunday 17th October (because of ICFP).




More information about the Libraries mailing list