{-# LANGUAGE TemplateHaskell #-}
module Control.Effect.Error
(
Error'(..)
, Error
, throwError
, catchError
, liftEither'
, liftEither
, runError'
, runError
, tagError'
, retagError'
, untagError'
) where
import Data.Coerce (coerce)
import Control.Monad.Trans.Except (ExceptT(ExceptT), catchE, throwE)
import Control.Effect.Machinery (G, Tagger(Tagger), Via(Via), makeTaggedEffect)
class Monad m => Error' tag e m | tag m -> e where
throwError' :: e -> m a
catchError' :: m a -> (e -> m a) -> m a
makeTaggedEffect ''Error'
instance Monad m => Error' tag e (ExceptT e m) where
throwError' :: e -> ExceptT e m a
throwError' = e -> ExceptT e m a
forall (m :: * -> *) e a. Monad m => e -> ExceptT e m a
throwE
{-# INLINE throwError' #-}
catchError' :: ExceptT e m a -> (e -> ExceptT e m a) -> ExceptT e m a
catchError' = ExceptT e m a -> (e -> ExceptT e m a) -> ExceptT e m a
forall (m :: * -> *) e a e'.
Monad m =>
ExceptT e m a -> (e -> ExceptT e' m a) -> ExceptT e' m a
catchE
{-# INLINE catchError' #-}
liftEither' :: forall tag e m a. Error' tag e m => Either e a -> m a
liftEither' :: Either e a -> m a
liftEither' = (e -> m a) -> (a -> m a) -> Either e a -> m a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall k (tag :: k) e (m :: * -> *) a. Error' tag e m => e -> m a
forall e (m :: * -> *) a. Error' tag e m => e -> m a
throwError' @tag) a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE liftEither' #-}
liftEither :: Error e m => Either e a -> m a
liftEither :: Either e a -> m a
liftEither = forall k (tag :: k) e (m :: * -> *) a.
Error' tag e m =>
Either e a -> m a
forall e (m :: * -> *) a. Error' G e m => Either e a -> m a
liftEither' @G
{-# INLINE liftEither #-}
runError' :: (Error' tag e `Via` ExceptT e) m a -> m (Either e a)
runError' :: Via (Error' tag e) (ExceptT e) m a -> m (Either e a)
runError' = Via (Error' tag e) (ExceptT e) m a -> m (Either e a)
forall a b. Coercible a b => a -> b
coerce
{-# INLINE runError' #-}
runError :: (Error e `Via` ExceptT e) m a -> m (Either e a)
runError :: Via (Error e) (ExceptT e) m a -> m (Either e a)
runError = Via (Error e) (ExceptT e) m a -> m (Either e a)
forall a b. Coercible a b => a -> b
coerce
{-# INLINE runError #-}