transformers-0.4.0.0: Concrete functor and monad transformers

Portabilityportable
Stabilityexperimental
Maintainerross@soi.city.ac.uk
Safe HaskellSafe-Inferred

Control.Monad.Trans.Error

Contents

Description

Deprecated: Use Control.Monad.Trans.Except instead

This monad transformer adds the ability to fail or throw exceptions to a monad.

A sequence of actions succeeds, producing a value, only if all the actions in the sequence are successful. If one fails with an error, the rest of the sequence is skipped and the composite action fails with that error.

If the value of the error is not required, the variant in Control.Monad.Trans.Maybe may be used instead.

Note: This module will be removed in a future release. Instead, use Control.Monad.Trans.Except, which does not restrict the exception type, and also includes a base exception monad.

Synopsis

The ErrorT monad transformer

class Error a whereSource

An exception to be thrown.

Minimal complete definition: noMsg or strMsg.

Methods

noMsg :: aSource

Creates an exception without a message. The default implementation is strMsg "".

strMsg :: String -> aSource

Creates an exception with a message. The default implementation of strMsg s is noMsg.

Instances

Error IOException 
ErrorList a => Error [a]

A string can be thrown as an error.

class ErrorList a whereSource

Workaround so that we can have a Haskell 98 instance Error String.

Methods

listMsg :: String -> [a]Source

Instances

newtype ErrorT e m a Source

The error monad transformer. It can be used to add error handling to other monads.

The ErrorT Monad structure is parameterized over two things:

  • e - The error type.
  • m - The inner monad.

The return function yields a successful computation, while >>= sequences two subcomputations, failing on the first error.

Constructors

ErrorT (m (Either e a)) 

Instances

Error e => MonadTrans (ErrorT e) 
(Monad m, Error e) => Monad (ErrorT e m) 
Functor m => Functor (ErrorT e m) 
(MonadFix m, Error e) => MonadFix (ErrorT e m) 
(Monad m, Error e) => MonadPlus (ErrorT e m) 
(Functor m, Monad m) => Applicative (ErrorT e m) 
Foldable f => Foldable (ErrorT e f) 
Traversable f => Traversable (ErrorT e f) 
(Functor m, Monad m, Error e) => Alternative (ErrorT e m) 
(Error e, MonadIO m) => MonadIO (ErrorT e m) 
(Show e, Show1 m) => Show1 (ErrorT e m) 
(Read e, Read1 m) => Read1 (ErrorT e m) 
(Ord e, Ord1 m) => Ord1 (ErrorT e m) 
(Eq e, Eq1 m) => Eq1 (ErrorT e m) 
(Eq e, Eq1 m, Eq a) => Eq (ErrorT e m a) 
(Ord e, Ord1 m, Ord a) => Ord (ErrorT e m a) 
(Read e, Read1 m, Read a) => Read (ErrorT e m a) 
(Show e, Show1 m, Show a) => Show (ErrorT e m a) 

runErrorT :: ErrorT e m a -> m (Either e a)Source

Inverse of ErrorT.

mapErrorT :: (m (Either e a) -> n (Either e' b)) -> ErrorT e m a -> ErrorT e' n bSource

Map the unwrapped computation using the given function.

Error operations

throwError :: (Monad m, Error e) => e -> ErrorT e m aSource

Signal an error value e.

catchErrorSource

Arguments

:: (Monad m, Error e) 
=> ErrorT e m a

the inner computation

-> (e -> ErrorT e m a)

a handler for errors in the inner computation

-> ErrorT e m a 

Handle an error.

Lifting other operations

liftCallCC :: CallCC m (Either e a) (Either e b) -> CallCC (ErrorT e m) a bSource

Lift a callCC operation to the new monad.

liftListen :: Monad m => Listen w m (Either e a) -> Listen w (ErrorT e m) aSource

Lift a listen operation to the new monad.

liftPass :: Monad m => Pass w m (Either e a) -> Pass w (ErrorT e m) aSource

Lift a pass operation to the new monad.

Examples

Wrapping an IO action that can throw an error e:

 type ErrorWithIO e a = ErrorT e IO a
 ==> ErrorT (IO (Either e a))

An IO monad wrapped in StateT inside of ErrorT:

 type ErrorAndStateWithIO e s a = ErrorT e (StateT s IO) a
 ==> ErrorT (StateT s IO (Either e a))
 ==> ErrorT (StateT (s -> IO (Either e a,s)))