#4343: Add throwSTM and generalize catchSTM
---------------------------------+------------------------------------------
Reporter: basvandijk | Owner:
Type: proposal | Status: new
Priority: normal | Component: libraries (other)
Version: 7.1 | Keywords: stm, exception, throw,
throwIO, throwSTM, catch, catchSTM
Testcase: | Blockedby:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
Currently the only way to throw an exception in an
[http://hackage.haskell.org/packages/archive/stm/2.1.1.2/doc/html/Control-
Monad-STM.html STM] transaction is via
[http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Control-
Exception.html#v:throw throw]. The `IO` monad has the
[http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Control-
Exception.html#v:throwIO 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}}}
Catching exceptions in the `IO` monad can be done with
[http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Control-
Exception.html#v:catch catch]:
{{{catch :: Exception e => IO a -> e -> IO a -> IO a}}}
Catching exception in the `STM` monad can be done with
[http://hackage.haskell.org/packages/archive/stm/2.1.1.2/doc/html/Control-
Monad-STM.html#v:catchSTM catchSTM]:
{{{catchSTM :: STM a -> (SomeException -> STM a) -> STM a}}}
However, it would be nice to generalize this function to any exception:
{{{catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a}}}
This makes it consistent with the `IO` catch function and allows packages
like: `exception-monads-fd/tf` to define instances for
[http://hackage.haskell.org/packages/archive/exception-monads-
tf/0.1/doc/html/Control-Monad-Exception.html#t:MonadException
MonadException].
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4343>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs