| Copyright | (c) 2009-2014 Peter Trsko. |
|---|---|
| License | BSD3 |
| Stability | provisional |
| Portability | NoImplicitPrelude, RankNTypes |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Control.Monad.TaggedException.Utilities
Description
Utility functions built on top of core API.
- bracket :: (Exception e, MonadMask m) => m a -> (a -> m b) -> (a -> Throws e m c) -> Throws e m c
- bracket' :: MonadMask m => m a -> (a -> m b) -> (a -> m c) -> m c
- bracket_ :: (Exception e, MonadMask m) => m a -> m b -> Throws e m c -> Throws e m c
- bracketOnError :: (Exception e, MonadMask m) => m a -> (a -> m b) -> (a -> Throws e m c) -> Throws e m c
- bracketOnError' :: MonadMask m => m a -> (a -> m b) -> (a -> m c) -> m c
- finally :: (Exception e, MonadMask m) => Throws e m a -> m b -> Throws e m a
- finally' :: MonadMask m => m a -> m b -> m a
Documentation
Arguments
| :: (Exception e, MonadMask m) | |
| => m a | Computation to run before |
| -> (a -> m b) | Computation to run after |
| -> (a -> Throws e m c) | Computation to run in-between |
| -> Throws e m c | Result of the in-between computation |
Run computation surrounded by acquire and release computations. The
release computation is executed even if "in-between" computation
raises exception. See also bracket', bracket_, bracketOnError,
and bracketOnError'.
Arguments
| :: MonadMask m | |
| => m a | Computation to run before |
| -> (a -> m b) | Computation to run after |
| -> (a -> m c) | Computation to run in-between |
| -> m c | Result of the in-between computation |
Run computation surrounded by acquire and release computations. The
release computation is executed even if "in-between" computation
raises exception. See also bracket, bracket_, bracketOnError, and
bracketOnError'.
Default implementation:
bracket' acq rel go = mask' $ \ restore -> do
x <- acq
r <- restore (go x) `onException'` rel x
_ <- rel x
return rArguments
| :: (Exception e, MonadMask m) | |
| => m a | Computation to run before |
| -> m b | Computation to run after |
| -> Throws e m c | Computation to run in-between |
| -> Throws e m c | Result of the in-between computation |
Variant of bracket.
bracket_ acq rel go = bracket acq (const rel) (const go)
Arguments
| :: (Exception e, MonadMask m) | |
| => m a | Computation to run before |
| -> (a -> m b) | Computation to run after if an exception was raised |
| -> (a -> Throws e m c) | Computation to run in-between |
| -> Throws e m c | Result of the in-between computation |
Version of bracket where "after" computation is executed only if
"in-between" computation raises exception.
Default implementation:
bracketOnError acq rel go = mask $ \ restore -> do
x <- liftT acq
restore (go x) `onException` rel xArguments
| :: MonadMask m | |
| => m a | Computation to run before |
| -> (a -> m b) | Computation to run after if an exception was raised |
| -> (a -> m c) | Computation to run in-between |
| -> m c | Result of the in-between computation |
Version of bracket where "after" computation is executed only if
"in-between" computation raises exception.
Default implementation:
bracketOnError' acq rel go = mask' $ \ restore -> do
x <- liftT acq
restore (go x) `onException'` rel xArguments
| :: (Exception e, MonadMask m) | |
| => Throws e m a | Computation to run first |
| -> m b | Computation to run afterward (even if exception |
| -> Throws e m a | Returns the result of the first computation |
Run computation afeter another even if exception was thrown. See also
finally', onException and onException'.
Default implementation:
m `finally` n = mask $ \ restore -> do
r <- restore m `onException` n
_ <- liftT n
return rArguments
| :: MonadMask m | |
| => m a | Computation to run first |
| -> m b | Computation to run afterward (even if some exception was raised) |
| -> m a | Returns the result of the first computation |
Run computation afeter another even if exception was thrown. See also
finally, onException and onException'.