lifted-base-0.1.1.1: lifted IO operations from the base library

Portabilitynon-portable (extended exceptions)
Stabilityexperimental
MaintainerBas van Dijk <v.dijk.bas@gmail.com>
Safe HaskellTrustworthy

Control.Exception.Lifted

Contents

Description

This is a wrapped version of Control.Exception with types generalized from IO to all monads in either MonadBase or MonadBaseControl.

Synopsis

Documentation

Throwing exceptions

throwIO :: (MonadBase IO m, Exception e) => e -> m a

Generalized version of throwIO.

ioError :: MonadBase IO m => IOError -> m a

Generalized version of ioError.

Catching exceptions

The catch functions

catch

Arguments

:: (MonadBaseControl IO m, Exception e) 
=> m a

The computation to run

-> (e -> m a)

Handler to invoke if an exception is raised

-> m a 

Generalized version of catch.

catches :: MonadBaseControl IO m => m a -> [Handler m a] -> m a

Generalized version of catches.

data Handler m a

Generalized version of Handler.

Constructors

forall e . Exception e => Handler (e -> m a) 

catchJust

Arguments

:: (MonadBaseControl IO m, Exception e) 
=> (e -> Maybe b)

Predicate to select exceptions

-> m a

Computation to run

-> (b -> m a)

Handler

-> m a 

Generalized version of catchJust.

The handle functions

handle :: (MonadBaseControl IO m, Exception e) => (e -> m a) -> m a -> m a

Generalized version of handle.

handleJust :: (MonadBaseControl IO m, Exception e) => (e -> Maybe b) -> (b -> m a) -> m a -> m a

Generalized version of handleJust.

The try functions

try :: (MonadBaseControl IO m, Exception e) => m a -> m (Either e a)

Generalized version of try.

tryJust :: (MonadBaseControl IO m, Exception e) => (e -> Maybe b) -> m a -> m (Either b a)

Generalized version of tryJust.

The evaluate function

evaluate :: MonadBase IO m => a -> m a

Generalized version of evaluate.

Asynchronous Exceptions

Asynchronous exception control

The following functions allow a thread to control delivery of asynchronous exceptions during a critical region.

mask :: MonadBaseControl IO m => ((forall a. m a -> m a) -> m b) -> m b

Generalized version of mask.

mask_ :: MonadBaseControl IO m => m a -> m a

Generalized version of mask_.

uninterruptibleMask :: MonadBaseControl IO m => ((forall a. m a -> m a) -> m b) -> m b

Generalized version of uninterruptibleMask.

uninterruptibleMask_ :: MonadBaseControl IO m => m a -> m a

Generalized version of uninterruptibleMask_.

getMaskingState :: MonadBase IO m => m MaskingState

Generalized version of getMaskingState.

Brackets

bracket

Arguments

:: MonadBaseControl IO m 
=> m a

computation to run first ("acquire resource")

-> (a -> m b)

computation to run last ("release resource")

-> (a -> m c)

computation to run in-between

-> m c 

Generalized version of bracket. Note, any monadic side effects in m of the "release" computation will be discarded; it is run only for its side effects in IO.

Note that when your acquire and release computations are of type IO it will be more efficient to write:

liftBaseOp (bracket acquire release)

bracket_

Arguments

:: MonadBaseControl IO m 
=> m a

computation to run first ("acquire resource")

-> m b

computation to run last ("release resource")

-> m c

computation to run in-between

-> m c 

Generalized version of bracket_. Note, any monadic side effects in m of both the "acquire" and "release" computations will be discarded. To keep the monadic side effects of the "acquire" computation, use bracket with constant functions instead.

Note that when your acquire and release computations are of type IO it will be more efficient to write:

liftBaseOp_ (bracket_ acquire release)

bracketOnError

Arguments

:: MonadBaseControl IO m 
=> m a

computation to run first ("acquire resource")

-> (a -> m b)

computation to run last ("release resource")

-> (a -> m c)

computation to run in-between

-> m c 

Generalized version of bracketOnError. Note, any monadic side effects in m of the "release" computation will be discarded.

Note that when your acquire and release computations are of type IO it will be more efficient to write:

liftBaseOp (bracketOnError acquire release)

Utilities

finally

Arguments

:: MonadBaseControl IO m 
=> m a

computation to run first

-> m b

computation to run afterward (even if an exception was raised)

-> m a 

Generalized version of finally. Note, any monadic side effects in m of the "afterward" computation will be discarded.

onException :: MonadBaseControl IO m => m a -> m b -> m a

Generalized version of onException. Note, any monadic side effects in m of the "afterward" computation will be discarded.