| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cardano.Api.Monad.Error
Description
This module serves purpose as a single source of abstractions used in handling MonadError and
ExceptT through 'cardano-api'.
Synopsis
- type MonadTransError e (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = (Monad m, MonadTrans t, MonadError e (t m))
- type MonadIOTransError e (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = (MonadIO m, MonadIO (t m), MonadCatch m, MonadTrans t, MonadError e (t m))
- liftExceptT :: forall e t (m :: Type -> Type) a. MonadTransError e t m => ExceptT e m a -> t m a
- modifyError :: forall e' t (m :: Type -> Type) e a. MonadTransError e' t m => (e -> e') -> ExceptT e m a -> t m a
- handleIOExceptionsWith :: (MonadError e' m, MonadCatch m, Exception e) => (e -> e') -> m a -> m a
- handleIOExceptionsLiftWith :: (MonadIOTransError e' t m, Exception e) => (e -> e') -> m a -> t m a
- hoistIOEither :: forall e t (m :: Type -> Type) a. MonadIOTransError e t m => IO (Either e a) -> t m a
- liftMaybe :: MonadError e m => e -> Maybe a -> m a
- failEither :: MonadFail m => Either String a -> m a
- failEitherWith :: MonadFail m => (e -> String) -> Either e a -> m a
- (?!) :: MonadError e m => Maybe a -> e -> m a
- (?!&) :: Either e a -> (e -> e') -> Either e' a
- liftEither :: MonadError e m => Either e a -> m a
- mapExcept :: (Either e a -> Either e' b) -> Except e a -> Except e' b
- mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b
- runExcept :: Except e a -> Either e a
- runExceptT :: ExceptT e m a -> m (Either e a)
- withExcept :: (e -> e') -> Except e a -> Except e' a
- class Monad m => MonadError e (m :: Type -> Type) | m -> e where
- throwError :: e -> m a
- catchError :: m a -> (e -> m a) -> m a
- newtype ExceptT e (m :: Type -> Type) a = ExceptT (m (Either e a))
- module Control.Monad.IO.Class
- module Control.Monad.Trans.Class
- module Control.Monad.Trans.Except
- mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b
- runExceptT :: ExceptT e m a -> m (Either e a)
- bimapExceptT :: forall (m :: Type -> Type) x y a b. Functor m => (x -> y) -> (a -> b) -> ExceptT x m a -> ExceptT y m b
- bracketExceptT :: forall (m :: Type -> Type) e a b c. Monad m => ExceptT e m a -> (a -> ExceptT e m b) -> (a -> ExceptT e m c) -> ExceptT e m c
- bracketExceptionT :: forall (m :: Type -> Type) e a c b. MonadMask m => ExceptT e m a -> (a -> ExceptT e m c) -> (a -> ExceptT e m b) -> ExceptT e m b
- catchExceptT :: (MonadCatch m, Exception e) => m a -> (e -> x) -> ExceptT x m a
- catchIOExceptT :: forall (m :: Type -> Type) a x. MonadIO m => IO a -> (IOException -> x) -> ExceptT x m a
- catchLeftT :: forall (m :: Type -> Type) e a. Monad m => ExceptT e m a -> (e -> ExceptT e m a) -> ExceptT e m a
- catchesExceptT :: (Foldable f, MonadCatch m) => m a -> f (Handler m x) -> ExceptT x m a
- exceptT :: Monad m => (x -> m b) -> (a -> m b) -> ExceptT x m a -> m b
- firstExceptT :: forall (m :: Type -> Type) x y a. Functor m => (x -> y) -> ExceptT x m a -> ExceptT y m a
- handleExceptT :: (MonadCatch m, Exception e) => (e -> x) -> m a -> ExceptT x m a
- handleIOExceptT :: forall (m :: Type -> Type) x a. MonadIO m => (IOException -> x) -> IO a -> ExceptT x m a
- handleLeftT :: forall (m :: Type -> Type) e a. Monad m => (e -> ExceptT e m a) -> ExceptT e m a -> ExceptT e m a
- handlesExceptT :: (Foldable f, MonadCatch m) => f (Handler m x) -> m a -> ExceptT x m a
- hoistEither :: forall (m :: Type -> Type) x a. Monad m => Either x a -> ExceptT x m a
- hoistExceptT :: (forall b. m b -> n b) -> ExceptT x m a -> ExceptT x n a
- hoistMaybe :: forall (m :: Type -> Type) x a. Monad m => x -> Maybe a -> ExceptT x m a
- hushM :: Monad m => Either e a -> (e -> m ()) -> m (Maybe a)
- left :: forall (m :: Type -> Type) x a. Monad m => x -> ExceptT x m a
- newExceptT :: m (Either x a) -> ExceptT x m a
- onLeft :: forall e x (m :: Type -> Type) a. Monad m => (e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
- onNothing :: forall x (m :: Type -> Type) a. Monad m => ExceptT x m a -> ExceptT x m (Maybe a) -> ExceptT x m a
- right :: forall (m :: Type -> Type) a x. Monad m => a -> ExceptT x m a
- secondExceptT :: forall (m :: Type -> Type) a b x. Functor m => (a -> b) -> ExceptT x m a -> ExceptT x m b
Documentation
type MonadTransError e (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = (Monad m, MonadTrans t, MonadError e (t m)) Source #
Convenience alias
type MonadIOTransError e (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = (MonadIO m, MonadIO (t m), MonadCatch m, MonadTrans t, MonadError e (t m)) Source #
Same as MonadTransError, but with also MonadIO constraint
liftExceptT :: forall e t (m :: Type -> Type) a. MonadTransError e t m => ExceptT e m a -> t m a Source #
Lift ExceptT into MonadTransError
Arguments
| :: forall e' t (m :: Type -> Type) e a. MonadTransError e' t m | |
| => (e -> e') | mapping function |
| -> ExceptT e m a | value |
| -> t m a | result with modified error |
Modify an ExceptT error and lift it to MonadError transformer stack.
This implementation avoids nesting problem of modifyError from mtl. The issue with modifyError (from
mtl) is that when you use it on a function, you actually end up with ExceptT e1 (ExceptT e2 m a):
modifyError (f :: e2 -> e1) (foo :: ExceptT e2 (ExceptT e1 m) a) :: ExceptT e1 m a
and if you use modifyError (mtl) again, the more nested you get e.g.
ExceptT e1 (ExceptT e2 (ExceptT e3 m a)). With a deeper monad stack you pay the overhead with every
use of >>=.
This function avoids that, but at the cost of limiting its application to transformers.
handleIOExceptionsWith Source #
Arguments
| :: (MonadError e' m, MonadCatch m, Exception e) | |
| => (e -> e') | mapping function |
| -> m a | action that can throw |
| -> m a | result with caught exception |
Wrap an exception and lift it into MonadError.
handleIOExceptionsLiftWith Source #
Arguments
| :: (MonadIOTransError e' t m, Exception e) | |
| => (e -> e') | mapping function |
| -> m a | action that can throw |
| -> t m a | action with caught error lifted into |
Wrap an exception and lift it into MonadError stack.
hoistIOEither :: forall e t (m :: Type -> Type) a. MonadIOTransError e t m => IO (Either e a) -> t m a Source #
Lift an IO action that returns Either into MonadIOTransError
Arguments
| :: MonadError e m | |
| => e | Error to throw, if |
| -> Maybe a | |
| -> m a |
Lift Maybe into MonadError
(?!) :: MonadError e m => Maybe a -> e -> m a infixl 8 Source #
Infix liftMaybe, with arguments flipped
liftEither :: MonadError e m => Either e a -> m a Source #
Lifts an into any Either e.MonadError e
do { val <- liftEither =<< action1; action2 }where action1 returns an Either to represent errors.
Since: mtl-2.2.2
mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b Source #
Map the unwrapped computation using the given function.
runExceptT(mapExceptTf m) = f (runExceptTm)
runExcept :: Except e a -> Either e a Source #
Extractor for computations in the exception monad.
(The inverse of except).
withExcept :: (e -> e') -> Except e a -> Except e' a Source #
Transform any exceptions thrown by the computation using the given
function (a specialization of withExceptT).
class Monad m => MonadError e (m :: Type -> Type) | m -> e where Source #
The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled.
Is parameterized over the type of error information and
the monad type constructor.
It is common to use as the monad type constructor
for an error monad in which error descriptions take the form of strings.
In that case and many other common cases the resulting monad is already defined
as an instance of the Either StringMonadError class.
You can also define your own error type and/or use a monad type constructor
other than or Either String.
In these cases you will have to explicitly define instances of the Either IOErrorMonadError
class.
(If you are using the deprecated Control.Monad.Error or
Control.Monad.Trans.Error, you may also have to define an Error instance.)
Methods
throwError :: e -> m a Source #
Is used within a monadic computation to begin exception processing.
catchError :: m a -> (e -> m a) -> m a Source #
A handler function to handle previous errors and return to normal execution. A common idiom is:
do { action1; action2; action3 } `catchError` handlerwhere the action functions can call throwError.
Note that handler and the do-block must have the same return type.
Instances
| MonadError IOException IO Source # | |
Defined in Control.Monad.Error.Class Methods throwError :: IOException -> IO a Source # catchError :: IO a -> (IOException -> IO a) -> IO a Source # | |
| MonadError BuiltinError BuiltinResult Source # |
|
Defined in PlutusCore.Builtin.Result Methods throwError :: BuiltinError -> BuiltinResult a Source # catchError :: BuiltinResult a -> (BuiltinError -> BuiltinResult a) -> BuiltinResult a Source # | |
| MonadError () EvaluationResult Source # | |
Defined in PlutusCore.Evaluation.Result Methods throwError :: () -> EvaluationResult a Source # catchError :: EvaluationResult a -> (() -> EvaluationResult a) -> EvaluationResult a Source # | |
| MonadError () Maybe Source # | Since: mtl-2.2.2 |
Defined in Control.Monad.Error.Class Methods throwError :: () -> Maybe a Source # catchError :: Maybe a -> (() -> Maybe a) -> Maybe a Source # | |
| MonadError e m => MonadError e (Free m) # | |
Defined in Control.Monad.Free Methods throwError :: e -> Free m a Source # catchError :: Free m a -> (e -> Free m a) -> Free m a Source # | |
| MonadError e (Either e) Source # | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> Either e a Source # catchError :: Either e a -> (e -> Either e a) -> Either e a Source # | |
| MonadError e m => MonadError e (GenT m) # | |
Defined in Hedgehog.Internal.Gen Methods throwError :: e -> GenT m a Source # catchError :: GenT m a -> (e -> GenT m a) -> GenT m a Source # | |
| MonadError e m => MonadError e (PropertyT m) # | |
Defined in Hedgehog.Internal.Property Methods throwError :: e -> PropertyT m a Source # catchError :: PropertyT m a -> (e -> PropertyT m a) -> PropertyT m a Source # | |
| MonadError e m => MonadError e (TestT m) # | |
Defined in Hedgehog.Internal.Property Methods throwError :: e -> TestT m a Source # catchError :: TestT m a -> (e -> TestT m a) -> TestT m a Source # | |
| MonadError e m => MonadError e (TreeT m) # | |
Defined in Hedgehog.Internal.Tree Methods throwError :: e -> TreeT m a Source # catchError :: TreeT m a -> (e -> TreeT m a) -> TreeT m a Source # | |
| MonadError e m => MonadError e (ListT m) # | |
Defined in ListT Methods throwError :: e -> ListT m a Source # catchError :: ListT m a -> (e -> ListT m a) -> ListT m a Source # | |
| MonadError e m => MonadError e (QuoteT m) Source # | |
Defined in PlutusCore.Quote Methods throwError :: e -> QuoteT m a Source # catchError :: QuoteT m a -> (e -> QuoteT m a) -> QuoteT m a Source # | |
| MonadError e m => MonadError e (ResourceT m) # | |
Defined in Control.Monad.Trans.Resource.Internal Methods throwError :: e -> ResourceT m a Source # catchError :: ResourceT m a -> (e -> ResourceT m a) -> ResourceT m a Source # | |
| MonadError e m => MonadError e (MaybeT m) Source # | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> MaybeT m a Source # catchError :: MaybeT m a -> (e -> MaybeT m a) -> MaybeT m a Source # | |
| MonadError e m => MonadError e (FailT e m) # | |
Defined in Control.Monad.Trans.Fail Methods throwError :: e -> FailT e m a Source # catchError :: FailT e m a -> (e -> FailT e m a) -> FailT e m a Source # | |
| MonadError e m => MonadError e (RandT g m) # | |
Defined in Control.Monad.Trans.Random.Lazy Methods throwError :: e -> RandT g m a Source # catchError :: RandT g m a -> (e -> RandT g m a) -> RandT g m a Source # | |
| MonadError e m => MonadError e (RandT g m) # | |
Defined in Control.Monad.Trans.Random.Strict Methods throwError :: e -> RandT g m a Source # catchError :: RandT g m a -> (e -> RandT g m a) -> RandT g m a Source # | |
| (Functor f, MonadError e m) => MonadError e (FreeT f m) # | |
Defined in Control.Monad.Trans.Free Methods throwError :: e -> FreeT f m a Source # catchError :: FreeT f m a -> (e -> FreeT f m a) -> FreeT f m a Source # | |
| (Monoid w, MonadError e m) => MonadError e (AccumT w m) Source # | Since: mtl-2.3 |
Defined in Control.Monad.Error.Class Methods throwError :: e -> AccumT w m a Source # catchError :: AccumT w m a -> (e -> AccumT w m a) -> AccumT w m a Source # | |
| Monad m => MonadError e (ExceptT e m) Source # | Since: mtl-2.2 |
Defined in Control.Monad.Error.Class Methods throwError :: e -> ExceptT e m a Source # catchError :: ExceptT e m a -> (e -> ExceptT e m a) -> ExceptT e m a Source # | |
| MonadError e m => MonadError e (IdentityT m) Source # | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> IdentityT m a Source # catchError :: IdentityT m a -> (e -> IdentityT m a) -> IdentityT m a Source # | |
| MonadError e m => MonadError e (ReaderT r m) Source # | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> ReaderT r m a Source # catchError :: ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a Source # | |
| MonadError e m => MonadError e (StateT s m) Source # | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> StateT s m a Source # catchError :: StateT s m a -> (e -> StateT s m a) -> StateT s m a Source # | |
| MonadError e m => MonadError e (StateT s m) Source # | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> StateT s m a Source # catchError :: StateT s m a -> (e -> StateT s m a) -> StateT s m a Source # | |
| (Monoid w, MonadError e m) => MonadError e (WriterT w m) Source # | Since: mtl-2.3 |
Defined in Control.Monad.Error.Class Methods throwError :: e -> WriterT w m a Source # catchError :: WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a Source # | |
| (Monoid w, MonadError e m) => MonadError e (WriterT w m) Source # | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> WriterT w m a Source # catchError :: WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a Source # | |
| (Monoid w, MonadError e m) => MonadError e (WriterT w m) Source # | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> WriterT w m a Source # catchError :: WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a Source # | |
| MonadError e m => MonadError e (ConduitT i o m) # | |
Defined in Data.Conduit.Internal.Conduit Methods throwError :: e -> ConduitT i o m a Source # catchError :: ConduitT i o m a -> (e -> ConduitT i o m a) -> ConduitT i o m a Source # | |
| MonadError e m => MonadError e (ParsecT s u m) Source # | |
Defined in Text.Parsec.Prim Methods throwError :: e -> ParsecT s u m a Source # catchError :: ParsecT s u m a -> (e -> ParsecT s u m a) -> ParsecT s u m a Source # | |
| (Monoid w, MonadError e m) => MonadError e (RWST r w s m) Source # | Since: mtl-2.3 |
Defined in Control.Monad.Error.Class Methods throwError :: e -> RWST r w s m a Source # catchError :: RWST r w s m a -> (e -> RWST r w s m a) -> RWST r w s m a Source # | |
| (Monoid w, MonadError e m) => MonadError e (RWST r w s m) Source # | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> RWST r w s m a Source # catchError :: RWST r w s m a -> (e -> RWST r w s m a) -> RWST r w s m a Source # | |
| (Monoid w, MonadError e m) => MonadError e (RWST r w s m) Source # | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> RWST r w s m a Source # catchError :: RWST r w s m a -> (e -> RWST r w s m a) -> RWST r w s m a Source # | |
| MonadError e m => MonadError e (Pipe l i o u m) # | |
Defined in Data.Conduit.Internal.Pipe Methods throwError :: e -> Pipe l i o u m a Source # catchError :: Pipe l i o u m a -> (e -> Pipe l i o u m a) -> Pipe l i o u m a Source # | |
| ThrowableBuiltins uni fun => MonadError (CekEvaluationException NamedDeBruijn uni fun) (CekM uni fun s) Source # | |
Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal Methods throwError :: CekEvaluationException NamedDeBruijn uni fun -> CekM uni fun s a Source # catchError :: CekM uni fun s a -> (CekEvaluationException NamedDeBruijn uni fun -> CekM uni fun s a) -> CekM uni fun s a Source # | |
newtype ExceptT e (m :: Type -> Type) a Source #
A monad transformer that adds exceptions to other monads.
ExceptT constructs a monad parameterized over two things:
- e - An arbitrary exception type.
- m - The inner monad.
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.
Instances
module Control.Monad.IO.Class
module Control.Monad.Trans.Class
module Control.Monad.Trans.Except
mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b Source #
Map the unwrapped computation using the given function.
runExceptT(mapExceptTf m) = f (runExceptTm)
bimapExceptT :: forall (m :: Type -> Type) x y a b. Functor m => (x -> y) -> (a -> b) -> ExceptT x m a -> ExceptT y m b #
bracketExceptT :: forall (m :: Type -> Type) e a b c. Monad m => ExceptT e m a -> (a -> ExceptT e m b) -> (a -> ExceptT e m c) -> ExceptT e m c #
bracketExceptionT :: forall (m :: Type -> Type) e a c b. MonadMask m => ExceptT e m a -> (a -> ExceptT e m c) -> (a -> ExceptT e m b) -> ExceptT e m b #
catchExceptT :: (MonadCatch m, Exception e) => m a -> (e -> x) -> ExceptT x m a #
catchIOExceptT :: forall (m :: Type -> Type) a x. MonadIO m => IO a -> (IOException -> x) -> ExceptT x m a #
catchLeftT :: forall (m :: Type -> Type) e a. Monad m => ExceptT e m a -> (e -> ExceptT e m a) -> ExceptT e m a #
catchesExceptT :: (Foldable f, MonadCatch m) => m a -> f (Handler m x) -> ExceptT x m a #
firstExceptT :: forall (m :: Type -> Type) x y a. Functor m => (x -> y) -> ExceptT x m a -> ExceptT y m a #
handleExceptT :: (MonadCatch m, Exception e) => (e -> x) -> m a -> ExceptT x m a #
handleIOExceptT :: forall (m :: Type -> Type) x a. MonadIO m => (IOException -> x) -> IO a -> ExceptT x m a #
handleLeftT :: forall (m :: Type -> Type) e a. Monad m => (e -> ExceptT e m a) -> ExceptT e m a -> ExceptT e m a #
handlesExceptT :: (Foldable f, MonadCatch m) => f (Handler m x) -> m a -> ExceptT x m a #
hoistExceptT :: (forall b. m b -> n b) -> ExceptT x m a -> ExceptT x n a #
newExceptT :: m (Either x a) -> ExceptT x m a #
onLeft :: forall e x (m :: Type -> Type) a. Monad m => (e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a #