tagged-exception-core-2.1.0.0: Reflect exceptions using phantom types.

Copyright(c) 2009-2014 Peter Trsko.
LicenseBSD3
Stabilityprovisional
PortabilityNoImplicitPrelude, RankNTypes
Safe HaskellSafe
LanguageHaskell2010

Control.Monad.TaggedException.Utilities

Description

Utility functions built on top of core API.

Synopsis

Documentation

bracket Source

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'.

bracket' Source

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 r

bracket_ Source

Arguments

:: (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)

bracketOnError Source

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 x

bracketOnError' Source

Arguments

:: 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 x

finally Source

Arguments

:: (Exception e, MonadMask m) 
=> Throws e m a

Computation to run first

-> m b

Computation to run afterward (even if exception e was raised)

-> 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 r

finally' Source

Arguments

:: 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'.