{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-}
module Control.Carrier.Throw.Either
(
runThrow
, ThrowC(..)
, module Control.Effect.Throw
) where
import Control.Algebra
import Control.Applicative (Alternative)
import Control.Carrier.Error.Either
import Control.Effect.Throw
import Control.Monad (MonadPlus)
import qualified Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
runThrow :: ThrowC e m a -> m (Either e a)
runThrow (ThrowC m) = runError m
newtype ThrowC e m a = ThrowC (ErrorC e m a)
deriving (Alternative, Applicative, Functor, Monad, Fail.MonadFail, MonadFix, MonadIO, MonadPlus, MonadTrans)
instance (Algebra sig m, Effect sig) => Algebra (Throw e :+: sig) (ThrowC e m) where
alg (L (Throw e)) = ThrowC (throwError e)
alg (R other) = ThrowC (alg (R (handleCoercible other)))