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

Copyright(c) 2009-2015, Peter Trško
LicenseBSD3
Stabilityprovisional
PortabilityNoImplicitPrelude, RankNTypes
Safe HaskellSafe
LanguageHaskell2010

Control.Monad.TaggedException.Utilities

Description

Deprecated: Use module Control.Monad.TaggedException.Core instead.

Utility functions built on top of core API.

Functions from this module were moved in to Control.Monad.TaggedException.Core, and this module became deprecated.

For compatibility reasons this module re-exports all functions that were previously defined here, but this module will be removed in the future. Please update your code to use Control.Monad.TaggedException.Core instead.

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

Implementated as:

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.

Implemented as:

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.

Implemented as:

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.

Implemented as:

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

Implemented as:

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