{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Control.Carrier.Fail.Either
(
runFail
, FailC(..)
, module Control.Effect.Fail
) where
import Control.Algebra
import Control.Applicative (Alternative(..))
import Control.Carrier.Throw.Either
import Control.Effect.Fail
import Control.Monad (MonadPlus(..))
import Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
runFail :: FailC m a -> m (Either String a)
runFail :: forall (m :: * -> *) a. FailC m a -> m (Either String a)
runFail (FailC ThrowC String m a
m) = ThrowC String m a -> m (Either String a)
forall e (m :: * -> *) a. ThrowC e m a -> m (Either e a)
runThrow ThrowC String m a
m
{-# INLINE runFail #-}
newtype FailC m a = FailC (ThrowC String m a)
deriving (Algebra (Fail :+: sig), Applicative (FailC m)
Applicative (FailC m) =>
(forall a. FailC m a)
-> (forall a. FailC m a -> FailC m a -> FailC m a)
-> (forall a. FailC m a -> FailC m [a])
-> (forall a. FailC m a -> FailC m [a])
-> Alternative (FailC m)
forall a. FailC m a
forall a. FailC m a -> FailC m [a]
forall a. FailC m a -> FailC m a -> FailC m a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall (m :: * -> *).
(Alternative m, Monad m) =>
Applicative (FailC m)
forall (m :: * -> *) a. (Alternative m, Monad m) => FailC m a
forall (m :: * -> *) a.
(Alternative m, Monad m) =>
FailC m a -> FailC m [a]
forall (m :: * -> *) a.
(Alternative m, Monad m) =>
FailC m a -> FailC m a -> FailC m a
$cempty :: forall (m :: * -> *) a. (Alternative m, Monad m) => FailC m a
empty :: forall a. FailC m a
$c<|> :: forall (m :: * -> *) a.
(Alternative m, Monad m) =>
FailC m a -> FailC m a -> FailC m a
<|> :: forall a. FailC m a -> FailC m a -> FailC m a
$csome :: forall (m :: * -> *) a.
(Alternative m, Monad m) =>
FailC m a -> FailC m [a]
some :: forall a. FailC m a -> FailC m [a]
$cmany :: forall (m :: * -> *) a.
(Alternative m, Monad m) =>
FailC m a -> FailC m [a]
many :: forall a. FailC m a -> FailC m [a]
Alternative, Functor (FailC m)
Functor (FailC m) =>
(forall a. a -> FailC m a)
-> (forall a b. FailC m (a -> b) -> FailC m a -> FailC m b)
-> (forall a b c.
(a -> b -> c) -> FailC m a -> FailC m b -> FailC m c)
-> (forall a b. FailC m a -> FailC m b -> FailC m b)
-> (forall a b. FailC m a -> FailC m b -> FailC m a)
-> Applicative (FailC m)
forall a. a -> FailC m a
forall a b. FailC m a -> FailC m b -> FailC m a
forall a b. FailC m a -> FailC m b -> FailC m b
forall a b. FailC m (a -> b) -> FailC m a -> FailC m b
forall a b c. (a -> b -> c) -> FailC m a -> FailC m b -> FailC m c
forall (m :: * -> *). Monad m => Functor (FailC m)
forall (m :: * -> *) a. Monad m => a -> FailC m a
forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m a
forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m b
forall (m :: * -> *) a b.
Monad m =>
FailC m (a -> b) -> FailC m a -> FailC m b
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c) -> FailC m a -> FailC m b -> FailC m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall (m :: * -> *) a. Monad m => a -> FailC m a
pure :: forall a. a -> FailC m a
$c<*> :: forall (m :: * -> *) a b.
Monad m =>
FailC m (a -> b) -> FailC m a -> FailC m b
<*> :: forall a b. FailC m (a -> b) -> FailC m a -> FailC m b
$cliftA2 :: forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c) -> FailC m a -> FailC m b -> FailC m c
liftA2 :: forall a b c. (a -> b -> c) -> FailC m a -> FailC m b -> FailC m c
$c*> :: forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m b
*> :: forall a b. FailC m a -> FailC m b -> FailC m b
$c<* :: forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m a
<* :: forall a b. FailC m a -> FailC m b -> FailC m a
Applicative, (forall a b. (a -> b) -> FailC m a -> FailC m b)
-> (forall a b. a -> FailC m b -> FailC m a) -> Functor (FailC m)
forall a b. a -> FailC m b -> FailC m a
forall a b. (a -> b) -> FailC m a -> FailC m b
forall (m :: * -> *) a b. Functor m => a -> FailC m b -> FailC m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> FailC m a -> FailC m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> FailC m a -> FailC m b
fmap :: forall a b. (a -> b) -> FailC m a -> FailC m b
$c<$ :: forall (m :: * -> *) a b. Functor m => a -> FailC m b -> FailC m a
<$ :: forall a b. a -> FailC m b -> FailC m a
Functor, Applicative (FailC m)
Applicative (FailC m) =>
(forall a b. FailC m a -> (a -> FailC m b) -> FailC m b)
-> (forall a b. FailC m a -> FailC m b -> FailC m b)
-> (forall a. a -> FailC m a)
-> Monad (FailC m)
forall a. a -> FailC m a
forall a b. FailC m a -> FailC m b -> FailC m b
forall a b. FailC m a -> (a -> FailC m b) -> FailC m b
forall (m :: * -> *). Monad m => Applicative (FailC m)
forall (m :: * -> *) a. Monad m => a -> FailC m a
forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m b
forall (m :: * -> *) a b.
Monad m =>
FailC m a -> (a -> FailC m b) -> FailC m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
FailC m a -> (a -> FailC m b) -> FailC m b
>>= :: forall a b. FailC m a -> (a -> FailC m b) -> FailC m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m b
>> :: forall a b. FailC m a -> FailC m b -> FailC m b
$creturn :: forall (m :: * -> *) a. Monad m => a -> FailC m a
return :: forall a. a -> FailC m a
Monad, Monad (FailC m)
Monad (FailC m) =>
(forall a. (a -> FailC m a) -> FailC m a) -> MonadFix (FailC m)
forall a. (a -> FailC m a) -> FailC m a
forall (m :: * -> *).
Monad m =>
(forall a. (a -> m a) -> m a) -> MonadFix m
forall (m :: * -> *). MonadFix m => Monad (FailC m)
forall (m :: * -> *) a. MonadFix m => (a -> FailC m a) -> FailC m a
$cmfix :: forall (m :: * -> *) a. MonadFix m => (a -> FailC m a) -> FailC m a
mfix :: forall a. (a -> FailC m a) -> FailC m a
MonadFix, Monad (FailC m)
Monad (FailC m) =>
(forall a. IO a -> FailC m a) -> MonadIO (FailC m)
forall a. IO a -> FailC m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (FailC m)
forall (m :: * -> *) a. MonadIO m => IO a -> FailC m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> FailC m a
liftIO :: forall a. IO a -> FailC m a
MonadIO, Monad (FailC m)
Alternative (FailC m)
(Alternative (FailC m), Monad (FailC m)) =>
(forall a. FailC m a)
-> (forall a. FailC m a -> FailC m a -> FailC m a)
-> MonadPlus (FailC m)
forall a. FailC m a
forall a. FailC m a -> FailC m a -> FailC m a
forall (m :: * -> *). (Alternative m, Monad m) => Monad (FailC m)
forall (m :: * -> *).
(Alternative m, Monad m) =>
Alternative (FailC m)
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
forall (m :: * -> *) a. (Alternative m, Monad m) => FailC m a
forall (m :: * -> *) a.
(Alternative m, Monad m) =>
FailC m a -> FailC m a -> FailC m a
$cmzero :: forall (m :: * -> *) a. (Alternative m, Monad m) => FailC m a
mzero :: forall a. FailC m a
$cmplus :: forall (m :: * -> *) a.
(Alternative m, Monad m) =>
FailC m a -> FailC m a -> FailC m a
mplus :: forall a. FailC m a -> FailC m a -> FailC m a
MonadPlus, (forall (m :: * -> *). Monad m => Monad (FailC m)) =>
(forall (m :: * -> *) a. Monad m => m a -> FailC m a)
-> MonadTrans FailC
forall (m :: * -> *). Monad m => Monad (FailC m)
forall (m :: * -> *) a. Monad m => m a -> FailC m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *). Monad m => Monad (t m)) =>
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
$clift :: forall (m :: * -> *) a. Monad m => m a -> FailC m a
lift :: forall (m :: * -> *) a. Monad m => m a -> FailC m a
MonadTrans)
instance Algebra sig m => Fail.MonadFail (FailC m) where
fail :: forall a. String -> FailC m a
fail = Throw String (FailC m) a -> FailC m a
forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
(m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send (Throw String (FailC m) a -> FailC m a)
-> (String -> Throw String (FailC m) a) -> String -> FailC m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Throw String (FailC m) a
forall (m :: * -> *) k. String -> Fail m k
Fail
{-# INLINE fail #-}