monad-control-0.1: Lift control operations, like exception catching, through monad transformers

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

Control.Exception.Control

Contents

Description

This is a wrapped version of Control.Exception with types generalized from IO to all monads in MonadControlIO.

Synopsis

Documentation

Throwing exceptions

throwIO :: (MonadIO m, Exception e) => e -> m aSource

Generalized version of throwIO.

ioError :: MonadIO m => IOError -> m aSource

Generalized version of ioError.

Catching exceptions

The catch functions

catchSource

Arguments

:: (MonadControlIO 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 :: MonadControlIO m => m a -> [Handler m a] -> m aSource

Generalized version of catches.

data Handler m a Source

Generalized version of Handler.

Constructors

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

catchJustSource

Arguments

:: (MonadControlIO 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 :: (MonadControlIO m, Exception e) => (e -> m a) -> m a -> m aSource

Generalized version of handle.

handleJust :: (MonadControlIO m, Exception e) => (e -> Maybe b) -> (b -> m a) -> m a -> m aSource

Generalized version of handleJust.

The try functions

try :: (MonadControlIO m, Exception e) => m a -> m (Either e a)Source

Generalized version of try.

tryJust :: (MonadControlIO m, Exception e) => (e -> Maybe b) -> m a -> m (Either b a)Source

Generalized version of tryJust.

The evaluate function

evaluate :: MonadIO m => a -> m aSource

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 :: MonadControlIO m => ((forall a. m a -> m a) -> m b) -> m bSource

Generalized version of mask.

mask_ :: MonadControlIO m => m a -> m aSource

Generalized version of mask_.

uninterruptibleMask :: MonadControlIO m => ((forall a. m a -> m a) -> m b) -> m bSource

Generalized version of uninterruptibleMask.

uninterruptibleMask_ :: MonadControlIO m => m a -> m aSource

Generalized version of uninterruptibleMask_.

getMaskingState :: MonadIO m => m MaskingStateSource

Generalized version of getMaskingState.

blocked :: MonadIO m => m BoolSource

Generalized version of blocked. returns True if asynchronous exceptions are blocked in the current thread.

Utilities

bracketSource

Arguments

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

bracket_ :: MonadControlIO m => m a -> m b -> m c -> m cSource

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.

bracketOnErrorSource

Arguments

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

finallySource

Arguments

:: MonadControlIO 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 :: MonadControlIO m => m a -> m b -> m aSource

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