module Control.Monad.Except.Class (
MonadError(..),
) where
import Control.Monad.Trans.Except (ExceptT)
import qualified Control.Monad.Trans.Except as ExceptT (throwE, catchE)
import Control.Monad.Trans.Identity as Identity
import Control.Monad.Trans.Maybe as Maybe
import Control.Monad.Trans.Reader as Reader
import Control.Monad.Trans.RWS.Lazy as LazyRWS
import Control.Monad.Trans.RWS.Strict as StrictRWS
import Control.Monad.Trans.State.Lazy as LazyState
import Control.Monad.Trans.State.Strict as StrictState
import Control.Monad.Trans.Writer.Lazy as LazyWriter
import Control.Monad.Trans.Writer.Strict as StrictWriter
import Control.Monad.Trans
import qualified Control.Exception
class (Monad m) => MonadError m where
type ErrorType m
throwError :: ErrorType m -> m a
catchError :: m a -> (ErrorType m -> m a) -> m a
instance MonadError IO where
type ErrorType IO = IOError
throwError :: forall a. ErrorType IO -> IO a
throwError = forall a. IOError -> IO a
ioError
catchError :: forall a. IO a -> (ErrorType IO -> IO a) -> IO a
catchError = forall e a. Exception e => IO a -> (e -> IO a) -> IO a
Control.Exception.catch
instance MonadError (Either e) where
type ErrorType (Either e) = e
throwError :: forall a. ErrorType (Either e) -> Either e a
throwError = forall a b. a -> Either a b
Left
Left e
l catchError :: forall a.
Either e a -> (ErrorType (Either e) -> Either e a) -> Either e a
`catchError` ErrorType (Either e) -> Either e a
h = ErrorType (Either e) -> Either e a
h e
l
Right a
r `catchError` ErrorType (Either e) -> Either e a
_ = forall a b. b -> Either a b
Right a
r
instance (Monad m) => MonadError (ExceptT e m) where
type ErrorType (ExceptT e m) = e
throwError :: forall a. ErrorType (ExceptT e m) -> ExceptT e m a
throwError = forall (m :: * -> *) e a. Monad m => e -> ExceptT e m a
ExceptT.throwE
catchError :: forall a.
ExceptT e m a
-> (ErrorType (ExceptT e m) -> ExceptT e m a) -> ExceptT e m a
catchError = forall (m :: * -> *) e a e'.
Monad m =>
ExceptT e m a -> (e -> ExceptT e' m a) -> ExceptT e' m a
ExceptT.catchE
instance (MonadError m) => MonadError (IdentityT m) where
type ErrorType (IdentityT m) = ErrorType m
throwError :: forall a. ErrorType (IdentityT m) -> IdentityT m a
throwError = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadError m => ErrorType m -> m a
throwError
catchError :: forall a.
IdentityT m a
-> (ErrorType (IdentityT m) -> IdentityT m a) -> IdentityT m a
catchError = forall {k} e (m :: k -> *) (a :: k).
Catch e m a -> Catch e (IdentityT m) a
Identity.liftCatch forall (m :: * -> *) a.
MonadError m =>
m a -> (ErrorType m -> m a) -> m a
catchError
instance (MonadError m) => MonadError (MaybeT m) where
type ErrorType (MaybeT m) = ErrorType m
throwError :: forall a. ErrorType (MaybeT m) -> MaybeT m a
throwError = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadError m => ErrorType m -> m a
throwError
catchError :: forall a.
MaybeT m a -> (ErrorType (MaybeT m) -> MaybeT m a) -> MaybeT m a
catchError = forall e (m :: * -> *) a.
Catch e m (Maybe a) -> Catch e (MaybeT m) a
Maybe.liftCatch forall (m :: * -> *) a.
MonadError m =>
m a -> (ErrorType m -> m a) -> m a
catchError
instance (MonadError m) => MonadError (ReaderT r m) where
type ErrorType (ReaderT r m) = ErrorType m
throwError :: forall a. ErrorType (ReaderT r m) -> ReaderT r m a
throwError = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadError m => ErrorType m -> m a
throwError
catchError :: forall a.
ReaderT r m a
-> (ErrorType (ReaderT r m) -> ReaderT r m a) -> ReaderT r m a
catchError = forall e (m :: * -> *) a r. Catch e m a -> Catch e (ReaderT r m) a
Reader.liftCatch forall (m :: * -> *) a.
MonadError m =>
m a -> (ErrorType m -> m a) -> m a
catchError
instance (Monoid w, MonadError m) => MonadError (LazyRWS.RWST r w s m) where
type ErrorType (LazyRWS.RWST r w s m) = ErrorType m
throwError :: forall a. ErrorType (RWST r w s m) -> RWST r w s m a
throwError = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadError m => ErrorType m -> m a
throwError
catchError :: forall a.
RWST r w s m a
-> (ErrorType (RWST r w s m) -> RWST r w s m a) -> RWST r w s m a
catchError = forall e (m :: * -> *) a s w r.
Catch e m (a, s, w) -> Catch e (RWST r w s m) a
LazyRWS.liftCatch forall (m :: * -> *) a.
MonadError m =>
m a -> (ErrorType m -> m a) -> m a
catchError
instance (Monoid w, MonadError m) => MonadError (StrictRWS.RWST r w s m) where
type ErrorType (StrictRWS.RWST r w s m) = ErrorType m
throwError :: forall a. ErrorType (RWST r w s m) -> RWST r w s m a
throwError = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadError m => ErrorType m -> m a
throwError
catchError :: forall a.
RWST r w s m a
-> (ErrorType (RWST r w s m) -> RWST r w s m a) -> RWST r w s m a
catchError = forall e (m :: * -> *) a s w r.
Catch e m (a, s, w) -> Catch e (RWST r w s m) a
StrictRWS.liftCatch forall (m :: * -> *) a.
MonadError m =>
m a -> (ErrorType m -> m a) -> m a
catchError
instance (MonadError m) => MonadError (LazyState.StateT s m) where
type ErrorType (LazyState.StateT s m) = ErrorType m
throwError :: forall a. ErrorType (StateT s m) -> StateT s m a
throwError = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadError m => ErrorType m -> m a
throwError
catchError :: forall a.
StateT s m a
-> (ErrorType (StateT s m) -> StateT s m a) -> StateT s m a
catchError = forall e (m :: * -> *) a s.
Catch e m (a, s) -> Catch e (StateT s m) a
LazyState.liftCatch forall (m :: * -> *) a.
MonadError m =>
m a -> (ErrorType m -> m a) -> m a
catchError
instance (MonadError m) => MonadError (StrictState.StateT s m) where
type ErrorType (StrictState.StateT s m) = ErrorType m
throwError :: forall a. ErrorType (StateT s m) -> StateT s m a
throwError = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadError m => ErrorType m -> m a
throwError
catchError :: forall a.
StateT s m a
-> (ErrorType (StateT s m) -> StateT s m a) -> StateT s m a
catchError = forall e (m :: * -> *) a s.
Catch e m (a, s) -> Catch e (StateT s m) a
StrictState.liftCatch forall (m :: * -> *) a.
MonadError m =>
m a -> (ErrorType m -> m a) -> m a
catchError
instance (Monoid w, MonadError m) => MonadError (LazyWriter.WriterT w m) where
type ErrorType (LazyWriter.WriterT w m) = ErrorType m
throwError :: forall a. ErrorType (WriterT w m) -> WriterT w m a
throwError = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadError m => ErrorType m -> m a
throwError
catchError :: forall a.
WriterT w m a
-> (ErrorType (WriterT w m) -> WriterT w m a) -> WriterT w m a
catchError = forall e (m :: * -> *) a w.
Catch e m (a, w) -> Catch e (WriterT w m) a
LazyWriter.liftCatch forall (m :: * -> *) a.
MonadError m =>
m a -> (ErrorType m -> m a) -> m a
catchError
instance (Monoid w, MonadError m) => MonadError (StrictWriter.WriterT w m) where
type ErrorType (StrictWriter.WriterT w m) = ErrorType m
throwError :: forall a. ErrorType (WriterT w m) -> WriterT w m a
throwError = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadError m => ErrorType m -> m a
throwError
catchError :: forall a.
WriterT w m a
-> (ErrorType (WriterT w m) -> WriterT w m a) -> WriterT w m a
catchError = forall e (m :: * -> *) a w.
Catch e m (a, w) -> Catch e (WriterT w m) a
StrictWriter.liftCatch forall (m :: * -> *) a.
MonadError m =>
m a -> (ErrorType m -> m a) -> m a
catchError