The Except monad
type Except e = ExceptT e Identity
The parameterizable exception monad, which is strict.
Computations are either exceptions (of any type) or normal values.
These computations are plain values, and are unrelated to the
Control.Exception mechanism, which is tied to the IO monad.
The return function returns a normal value, while >>= exits on
the first exception. For a variant that continues after an error
and collects all the errors, see Errors.
except :: (Monad m) => Either e a -> ExceptT e m a
Constructor for computations in the exception monad.
(The inverse of runExcept).
runExcept :: Except e a -> Either e a
Extractor for computations in the exception monad.
(The inverse of except).
mapExcept :: (Either e a -> Either e' b) -> Except e a -> Except e' b
Map the unwrapped computation using the given function.
withExcept :: (e -> e') -> Except e a -> Except e' a
Transform any exceptions thrown by the computation using the given
function (a specialization of withExceptT).
A monad transformer that adds exceptions to other monads.
ExceptT constructs a strict monad parameterized over two things:
The monadic computations are a plain values. They are unrelated to
the Control.Exception mechanism, which is tied to the IO monad.
The return function yields a computation that produces the given
value, while >>= sequences two subcomputations, exiting on the
first exception.
ExceptT :: m (Either e a) -> ExceptT e m a
runExceptT :: ExceptT e m a -> m (Either e a)
mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b
Map the unwrapped computation using the given function.
withExceptT :: (Functor m) => (e -> e') -> ExceptT e m a -> ExceptT e' m a
Transform any exceptions thrown by the computation using the
given function.
Exception operations
throwE :: (Monad m) => e -> ExceptT e m a
Signal an exception value e.
catchE :: (Monad m) => ExceptT e m a -> (e -> ExceptT e' m a) -> ExceptT e' m a
Handle an exception.
the inner computation
(e -> ExceptT e' m a)a handler for exceptions in the inner
computation
handleE :: Monad m => (e -> ExceptT e' m a) -> ExceptT e m a -> ExceptT e' m a
The same as flip catchE, which is useful in situations where
the code for the handler is shorter.
tryE :: Monad m => ExceptT e m a -> ExceptT e m (Either e a)
Similar to catchE, but returns an Either result which is
(Right a) if no exception was thown, or (Left ex) if an
exception ex was thrown.
finallyE :: Monad m => ExceptT e m a -> ExceptT e m () -> ExceptT e m a
finallyE a b executes computation a followed by computation b,
even if a exits early by throwing an exception. In the latter case,
the exception is re-thrown after b has been executed.
onE :: (Monad m) => ExceptT e m a -> ExceptT e m b -> ExceptT e m a
If the first action succeeds, return its value, ignoring the
second action. If the first action throws an exception, run the
second action and then throw an exception, either the one thrown by
the second action, if any, or the one thrown by the first action.
Lifting other operations
liftCallCC :: CallCC m (Either e a) (Either e b) -> CallCC (ExceptT e m) a b
Lift a callCC operation to the new monad.
liftListen :: (Monad m) => Listen w m (Either e a) -> Listen w (ExceptT e m) a
Lift a listen operation to the new monad.
liftPass :: (Monad m) => Pass w m (Either e a) -> Pass w (ExceptT e m) a
Lift a pass operation to the new monad.
Instances
23
instance (Generic e, Generic m, Generic a) => Generic (ExceptT e m a)instance (Generic1 e, Generic1 m, Generic1 a) => Generic1 (ExceptT e m a)instance (Eq e, Eq1 m) => Eq1 (ExceptT e m)instance (Ord e, Ord1 m) => Ord1 (ExceptT e m)instance (Read e, Read1 m) => Read1 (ExceptT e m)instance (Show e, Show1 m) => Show1 (ExceptT e m)instance (Eq e, Eq1 m, Eq a) => Eq (ExceptT e m a)instance (Ord e, Ord1 m, Ord a) => Ord (ExceptT e m a)instance (Read e, Read1 m, Read a) => Read (ExceptT e m a)instance (Show e, Show1 m, Show a) => Show (ExceptT e m a)instance (Functor m) => Functor (ExceptT e m)instance (Foldable f) => Foldable (ExceptT e f)instance (Traversable f) => Traversable (ExceptT e f)instance (Functor m, Monad m) => Applicative (ExceptT e m)instance (Functor m, Monad m, Monoid e) => Alternative (ExceptT e m)instance (Monad m) => Monad (ExceptT e m)instance (Fail.MonadFail m) => Fail.MonadFail (ExceptT e m)instance (Monad m, Monoid e) => MonadPlus (ExceptT e m)instance (MonadFix m) => MonadFix (ExceptT e m)instance MonadTrans (ExceptT e)instance (MonadIO m) => MonadIO (ExceptT e m)instance (MonadZip m) => MonadZip (ExceptT e m)instance Contravariant m => Contravariant (ExceptT e m)
- Maintainer
- R.Paterson@city.ac.uk
- Portability
- portable
- Copyright
- (C) 2013 Ross Paterson
- License
- BSD-style (see the file LICENSE)