Portability | portable |
---|---|
Stability | experimental |
Maintainer | libraries@haskell.org |
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.
- class Error a where
- class ErrorList a where
- newtype ErrorT e m a = ErrorT {}
- mapErrorT :: (m (Either e a) -> n (Either e' b)) -> ErrorT e m a -> ErrorT e' n b
- throwError :: (Monad m, Error e) => e -> ErrorT e m a
- catchError :: (Monad m, Error e) => ErrorT e m a -> (e -> ErrorT e m a) -> ErrorT e m a
- liftCallCC :: (((Either e a -> m (Either e b)) -> m (Either e a)) -> m (Either e a)) -> ((a -> ErrorT e m b) -> ErrorT e m a) -> ErrorT e m a
- liftListen :: Monad m => (m (Either e a) -> m (Either e a, w)) -> ErrorT e m a -> ErrorT e m (a, w)
- liftPass :: Monad m => (m (Either e a, w -> w) -> m (Either e a)) -> ErrorT e m (a, w -> w) -> ErrorT e m a
The ErrorT monad transformer
Creates an exception without a message.
The default implementation is
.
strMsg
""
Error IOException | |
ErrorList a => Error [a] | A string can be thrown as an error. |
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.
Here are some examples of use:
-- wraps IO action that can throw an error e type ErrorWithIO e a = ErrorT e IO a ==> ErrorT (IO (Either e a)) -- 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)))
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) | |
(Functor m, Monad m, Error e) => Alternative (ErrorT e m) | |
(Error e, MonadIO m) => MonadIO (ErrorT e m) |
throwError :: (Monad m, Error e) => e -> ErrorT e m aSource
Signal an error
catchError :: (Monad m, Error e) => ErrorT e m a -> (e -> ErrorT e m a) -> ErrorT e m aSource
Handle an error
Lifting other operations
liftCallCC :: (((Either e a -> m (Either e b)) -> m (Either e a)) -> m (Either e a)) -> ((a -> ErrorT e m b) -> ErrorT e m a) -> ErrorT e m aSource
Lift a callCC
operation to the new monad.