{-# LANGUAGE DerivingVia #-}
module Control.Effect.Embed
  ( -- * Effects
    Embed(..)

    -- * Actions
  , embed

    -- * Interpreters
  , runM
  , runEmbed

  , embedToEmbed

  , embedToMonadBase

  , embedToMonadIO

    -- * Simple variants
  , embedToEmbedSimple

    -- * Carriers
  , RunMC(RunMC)
  , EmbedC(EmbedC)
  , EmbedToMonadBaseC
  , EmbedToMonadIOC
  ) where

import Data.Coerce
import Control.Applicative
import Control.Monad
import Control.Monad.Fix
import Control.Monad.Trans.Identity
import qualified Control.Monad.Fail as Fail
import Control.Effect.Internal
import Control.Effect.Carrier.Internal.Interpret
import Control.Effect.Type.Embed
import Control.Effect.Internal.Union
import Control.Effect.Internal.Utils
import Control.Monad.Base
import Control.Monad.Trans
import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
import Control.Monad.Trans.Control (MonadBaseControl, MonadTransControl)

embed :: Eff (Embed b) m => b a -> m a
embed :: b a -> m a
embed = Embed b m a -> m a
forall (e :: Effect) (m :: * -> *) a.
(Member e (Derivs m), Carrier m) =>
e m a -> m a
send (Embed b m a -> m a) -> (b a -> Embed b m a) -> b a -> m a
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# b a -> Embed b m a
forall k (b :: k -> *) (a :: k) (m :: * -> *). b a -> Embed b m a
Embed
{-# INLINE embed #-}

-- | The carrier for 'runM', which carries no effects but @'Embed' m@.
newtype RunMC m a = RunMC { RunMC m a -> m a
unRunMC :: m a }
  deriving ( a -> RunMC m b -> RunMC m a
(a -> b) -> RunMC m a -> RunMC m b
(forall a b. (a -> b) -> RunMC m a -> RunMC m b)
-> (forall a b. a -> RunMC m b -> RunMC m a) -> Functor (RunMC m)
forall a b. a -> RunMC m b -> RunMC m a
forall a b. (a -> b) -> RunMC m a -> RunMC m b
forall (m :: * -> *) a b. Functor m => a -> RunMC m b -> RunMC m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> RunMC m a -> RunMC m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> RunMC m b -> RunMC m a
$c<$ :: forall (m :: * -> *) a b. Functor m => a -> RunMC m b -> RunMC m a
fmap :: (a -> b) -> RunMC m a -> RunMC m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> RunMC m a -> RunMC m b
Functor, Functor (RunMC m)
a -> RunMC m a
Functor (RunMC m)
-> (forall a. a -> RunMC m a)
-> (forall a b. RunMC m (a -> b) -> RunMC m a -> RunMC m b)
-> (forall a b c.
    (a -> b -> c) -> RunMC m a -> RunMC m b -> RunMC m c)
-> (forall a b. RunMC m a -> RunMC m b -> RunMC m b)
-> (forall a b. RunMC m a -> RunMC m b -> RunMC m a)
-> Applicative (RunMC m)
RunMC m a -> RunMC m b -> RunMC m b
RunMC m a -> RunMC m b -> RunMC m a
RunMC m (a -> b) -> RunMC m a -> RunMC m b
(a -> b -> c) -> RunMC m a -> RunMC m b -> RunMC m c
forall a. a -> RunMC m a
forall a b. RunMC m a -> RunMC m b -> RunMC m a
forall a b. RunMC m a -> RunMC m b -> RunMC m b
forall a b. RunMC m (a -> b) -> RunMC m a -> RunMC m b
forall a b c. (a -> b -> c) -> RunMC m a -> RunMC m b -> RunMC 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
forall (m :: * -> *). Applicative m => Functor (RunMC m)
forall (m :: * -> *) a. Applicative m => a -> RunMC m a
forall (m :: * -> *) a b.
Applicative m =>
RunMC m a -> RunMC m b -> RunMC m a
forall (m :: * -> *) a b.
Applicative m =>
RunMC m a -> RunMC m b -> RunMC m b
forall (m :: * -> *) a b.
Applicative m =>
RunMC m (a -> b) -> RunMC m a -> RunMC m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> RunMC m a -> RunMC m b -> RunMC m c
<* :: RunMC m a -> RunMC m b -> RunMC m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
RunMC m a -> RunMC m b -> RunMC m a
*> :: RunMC m a -> RunMC m b -> RunMC m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
RunMC m a -> RunMC m b -> RunMC m b
liftA2 :: (a -> b -> c) -> RunMC m a -> RunMC m b -> RunMC m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> RunMC m a -> RunMC m b -> RunMC m c
<*> :: RunMC m (a -> b) -> RunMC m a -> RunMC m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
RunMC m (a -> b) -> RunMC m a -> RunMC m b
pure :: a -> RunMC m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> RunMC m a
$cp1Applicative :: forall (m :: * -> *). Applicative m => Functor (RunMC m)
Applicative, Applicative (RunMC m)
a -> RunMC m a
Applicative (RunMC m)
-> (forall a b. RunMC m a -> (a -> RunMC m b) -> RunMC m b)
-> (forall a b. RunMC m a -> RunMC m b -> RunMC m b)
-> (forall a. a -> RunMC m a)
-> Monad (RunMC m)
RunMC m a -> (a -> RunMC m b) -> RunMC m b
RunMC m a -> RunMC m b -> RunMC m b
forall a. a -> RunMC m a
forall a b. RunMC m a -> RunMC m b -> RunMC m b
forall a b. RunMC m a -> (a -> RunMC m b) -> RunMC m b
forall (m :: * -> *). Monad m => Applicative (RunMC m)
forall (m :: * -> *) a. Monad m => a -> RunMC m a
forall (m :: * -> *) a b.
Monad m =>
RunMC m a -> RunMC m b -> RunMC m b
forall (m :: * -> *) a b.
Monad m =>
RunMC m a -> (a -> RunMC m b) -> RunMC 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
return :: a -> RunMC m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> RunMC m a
>> :: RunMC m a -> RunMC m b -> RunMC m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
RunMC m a -> RunMC m b -> RunMC m b
>>= :: RunMC m a -> (a -> RunMC m b) -> RunMC m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
RunMC m a -> (a -> RunMC m b) -> RunMC m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (RunMC m)
Monad
           , Applicative (RunMC m)
RunMC m a
Applicative (RunMC m)
-> (forall a. RunMC m a)
-> (forall a. RunMC m a -> RunMC m a -> RunMC m a)
-> (forall a. RunMC m a -> RunMC m [a])
-> (forall a. RunMC m a -> RunMC m [a])
-> Alternative (RunMC m)
RunMC m a -> RunMC m a -> RunMC m a
RunMC m a -> RunMC m [a]
RunMC m a -> RunMC m [a]
forall a. RunMC m a
forall a. RunMC m a -> RunMC m [a]
forall a. RunMC m a -> RunMC m a -> RunMC 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 => Applicative (RunMC m)
forall (m :: * -> *) a. Alternative m => RunMC m a
forall (m :: * -> *) a. Alternative m => RunMC m a -> RunMC m [a]
forall (m :: * -> *) a.
Alternative m =>
RunMC m a -> RunMC m a -> RunMC m a
many :: RunMC m a -> RunMC m [a]
$cmany :: forall (m :: * -> *) a. Alternative m => RunMC m a -> RunMC m [a]
some :: RunMC m a -> RunMC m [a]
$csome :: forall (m :: * -> *) a. Alternative m => RunMC m a -> RunMC m [a]
<|> :: RunMC m a -> RunMC m a -> RunMC m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
RunMC m a -> RunMC m a -> RunMC m a
empty :: RunMC m a
$cempty :: forall (m :: * -> *) a. Alternative m => RunMC m a
$cp1Alternative :: forall (m :: * -> *). Alternative m => Applicative (RunMC m)
Alternative, Monad (RunMC m)
Alternative (RunMC m)
RunMC m a
Alternative (RunMC m)
-> Monad (RunMC m)
-> (forall a. RunMC m a)
-> (forall a. RunMC m a -> RunMC m a -> RunMC m a)
-> MonadPlus (RunMC m)
RunMC m a -> RunMC m a -> RunMC m a
forall a. RunMC m a
forall a. RunMC m a -> RunMC m a -> RunMC m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
forall (m :: * -> *). MonadPlus m => Monad (RunMC m)
forall (m :: * -> *). MonadPlus m => Alternative (RunMC m)
forall (m :: * -> *) a. MonadPlus m => RunMC m a
forall (m :: * -> *) a.
MonadPlus m =>
RunMC m a -> RunMC m a -> RunMC m a
mplus :: RunMC m a -> RunMC m a -> RunMC m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
RunMC m a -> RunMC m a -> RunMC m a
mzero :: RunMC m a
$cmzero :: forall (m :: * -> *) a. MonadPlus m => RunMC m a
$cp2MonadPlus :: forall (m :: * -> *). MonadPlus m => Monad (RunMC m)
$cp1MonadPlus :: forall (m :: * -> *). MonadPlus m => Alternative (RunMC m)
MonadPlus
           , Monad (RunMC m)
Monad (RunMC m)
-> (forall a. (a -> RunMC m a) -> RunMC m a) -> MonadFix (RunMC m)
(a -> RunMC m a) -> RunMC m a
forall a. (a -> RunMC m a) -> RunMC m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
forall (m :: * -> *). MonadFix m => Monad (RunMC m)
forall (m :: * -> *) a. MonadFix m => (a -> RunMC m a) -> RunMC m a
mfix :: (a -> RunMC m a) -> RunMC m a
$cmfix :: forall (m :: * -> *) a. MonadFix m => (a -> RunMC m a) -> RunMC m a
$cp1MonadFix :: forall (m :: * -> *). MonadFix m => Monad (RunMC m)
MonadFix, Monad (RunMC m)
Monad (RunMC m)
-> (forall a. String -> RunMC m a) -> MonadFail (RunMC m)
String -> RunMC m a
forall a. String -> RunMC m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
forall (m :: * -> *). MonadFail m => Monad (RunMC m)
forall (m :: * -> *) a. MonadFail m => String -> RunMC m a
fail :: String -> RunMC m a
$cfail :: forall (m :: * -> *) a. MonadFail m => String -> RunMC m a
$cp1MonadFail :: forall (m :: * -> *). MonadFail m => Monad (RunMC m)
Fail.MonadFail, Monad (RunMC m)
Monad (RunMC m)
-> (forall a. IO a -> RunMC m a) -> MonadIO (RunMC m)
IO a -> RunMC m a
forall a. IO a -> RunMC m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (RunMC m)
forall (m :: * -> *) a. MonadIO m => IO a -> RunMC m a
liftIO :: IO a -> RunMC m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> RunMC m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (RunMC m)
MonadIO
           , Monad (RunMC m)
e -> RunMC m a
Monad (RunMC m)
-> (forall e a. Exception e => e -> RunMC m a)
-> MonadThrow (RunMC m)
forall e a. Exception e => e -> RunMC m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
forall (m :: * -> *). MonadThrow m => Monad (RunMC m)
forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> RunMC m a
throwM :: e -> RunMC m a
$cthrowM :: forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> RunMC m a
$cp1MonadThrow :: forall (m :: * -> *). MonadThrow m => Monad (RunMC m)
MonadThrow, MonadThrow (RunMC m)
MonadThrow (RunMC m)
-> (forall e a.
    Exception e =>
    RunMC m a -> (e -> RunMC m a) -> RunMC m a)
-> MonadCatch (RunMC m)
RunMC m a -> (e -> RunMC m a) -> RunMC m a
forall e a.
Exception e =>
RunMC m a -> (e -> RunMC m a) -> RunMC m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
forall (m :: * -> *). MonadCatch m => MonadThrow (RunMC m)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
RunMC m a -> (e -> RunMC m a) -> RunMC m a
catch :: RunMC m a -> (e -> RunMC m a) -> RunMC m a
$ccatch :: forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
RunMC m a -> (e -> RunMC m a) -> RunMC m a
$cp1MonadCatch :: forall (m :: * -> *). MonadCatch m => MonadThrow (RunMC m)
MonadCatch, MonadCatch (RunMC m)
MonadCatch (RunMC m)
-> (forall b.
    ((forall a. RunMC m a -> RunMC m a) -> RunMC m b) -> RunMC m b)
-> (forall b.
    ((forall a. RunMC m a -> RunMC m a) -> RunMC m b) -> RunMC m b)
-> (forall a b c.
    RunMC m a
    -> (a -> ExitCase b -> RunMC m c)
    -> (a -> RunMC m b)
    -> RunMC m (b, c))
-> MonadMask (RunMC m)
RunMC m a
-> (a -> ExitCase b -> RunMC m c)
-> (a -> RunMC m b)
-> RunMC m (b, c)
((forall a. RunMC m a -> RunMC m a) -> RunMC m b) -> RunMC m b
((forall a. RunMC m a -> RunMC m a) -> RunMC m b) -> RunMC m b
forall b.
((forall a. RunMC m a -> RunMC m a) -> RunMC m b) -> RunMC m b
forall a b c.
RunMC m a
-> (a -> ExitCase b -> RunMC m c)
-> (a -> RunMC m b)
-> RunMC m (b, c)
forall (m :: * -> *).
MonadCatch m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
    m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
forall (m :: * -> *). MonadMask m => MonadCatch (RunMC m)
forall (m :: * -> *) b.
MonadMask m =>
((forall a. RunMC m a -> RunMC m a) -> RunMC m b) -> RunMC m b
forall (m :: * -> *) a b c.
MonadMask m =>
RunMC m a
-> (a -> ExitCase b -> RunMC m c)
-> (a -> RunMC m b)
-> RunMC m (b, c)
generalBracket :: RunMC m a
-> (a -> ExitCase b -> RunMC m c)
-> (a -> RunMC m b)
-> RunMC m (b, c)
$cgeneralBracket :: forall (m :: * -> *) a b c.
MonadMask m =>
RunMC m a
-> (a -> ExitCase b -> RunMC m c)
-> (a -> RunMC m b)
-> RunMC m (b, c)
uninterruptibleMask :: ((forall a. RunMC m a -> RunMC m a) -> RunMC m b) -> RunMC m b
$cuninterruptibleMask :: forall (m :: * -> *) b.
MonadMask m =>
((forall a. RunMC m a -> RunMC m a) -> RunMC m b) -> RunMC m b
mask :: ((forall a. RunMC m a -> RunMC m a) -> RunMC m b) -> RunMC m b
$cmask :: forall (m :: * -> *) b.
MonadMask m =>
((forall a. RunMC m a -> RunMC m a) -> RunMC m b) -> RunMC m b
$cp1MonadMask :: forall (m :: * -> *). MonadMask m => MonadCatch (RunMC m)
MonadMask
           , MonadBase b, MonadBaseControl b
           )
  deriving (m a -> RunMC m a
(forall (m :: * -> *) a. Monad m => m a -> RunMC m a)
-> MonadTrans RunMC
forall (m :: * -> *) a. Monad m => m a -> RunMC m a
forall (t :: Effect).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> RunMC m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> RunMC m a
MonadTrans, MonadTrans RunMC
m (StT RunMC a) -> RunMC m a
MonadTrans RunMC
-> (forall (m :: * -> *) a.
    Monad m =>
    (Run RunMC -> m a) -> RunMC m a)
-> (forall (m :: * -> *) a.
    Monad m =>
    m (StT RunMC a) -> RunMC m a)
-> MonadTransControl RunMC
(Run RunMC -> m a) -> RunMC m a
forall (m :: * -> *) a. Monad m => m (StT RunMC a) -> RunMC m a
forall (m :: * -> *) a. Monad m => (Run RunMC -> m a) -> RunMC m a
forall (t :: Effect).
MonadTrans t
-> (forall (m :: * -> *) a. Monad m => (Run t -> m a) -> t m a)
-> (forall (m :: * -> *) a. Monad m => m (StT t a) -> t m a)
-> MonadTransControl t
restoreT :: m (StT RunMC a) -> RunMC m a
$crestoreT :: forall (m :: * -> *) a. Monad m => m (StT RunMC a) -> RunMC m a
liftWith :: (Run RunMC -> m a) -> RunMC m a
$cliftWith :: forall (m :: * -> *) a. Monad m => (Run RunMC -> m a) -> RunMC m a
$cp1MonadTransControl :: MonadTrans RunMC
MonadTransControl) via IdentityT

instance Monad m => Carrier (RunMC m) where
  type Derivs (RunMC m) = '[Embed m]
  type Prims  (RunMC m) = '[]

  algPrims :: Algebra' (Prims (RunMC m)) (RunMC m) a
algPrims = Algebra' (Prims (RunMC m)) (RunMC m) a
forall (m :: * -> *) a b. Union '[] m a -> b
absurdU
  {-# INLINE algPrims #-}

  reformulate :: Reformulation' (Derivs (RunMC m)) (Prims (RunMC m)) (RunMC m) z a
reformulate forall x. RunMC m x -> z x
n Algebra (Prims (RunMC m)) z
_ Union (Derivs (RunMC m)) z a
u = RunMC m a -> z a
forall x. RunMC m x -> z x
n (m a -> RunMC m a
forall k (m :: k -> *) (a :: k). m a -> RunMC m a
RunMC (Embed m z a -> m a
forall k (b :: k -> *) (m :: * -> *) (a :: k). Embed b m a -> b a
unEmbed (Union '[Embed m] z a -> Embed m z a
forall (e :: Effect) (m :: * -> *) a.
RepresentationalEff e =>
Union '[e] m a -> e m a
extract Union '[Embed m] z a
Union (Derivs (RunMC m)) z a
u)))
  {-# INLINE reformulate #-}

  algDerivs :: Algebra' (Derivs (RunMC m)) (RunMC m) a
algDerivs Union (Derivs (RunMC m)) (RunMC m) a
u = m a -> RunMC m a
forall k (m :: k -> *) (a :: k). m a -> RunMC m a
RunMC (Embed m (RunMC m) a -> m a
forall k (b :: k -> *) (m :: * -> *) (a :: k). Embed b m a -> b a
unEmbed (Union '[Embed m] (RunMC m) a -> Embed m (RunMC m) a
forall (e :: Effect) (m :: * -> *) a.
RepresentationalEff e =>
Union '[e] m a -> e m a
extract Union '[Embed m] (RunMC m) a
Union (Derivs (RunMC m)) (RunMC m) a
u))
  {-# INLINE algDerivs #-}

newtype EmbedC m a = EmbedC { EmbedC m a -> m a
unEmbedC :: m a }
  deriving ( a -> EmbedC m b -> EmbedC m a
(a -> b) -> EmbedC m a -> EmbedC m b
(forall a b. (a -> b) -> EmbedC m a -> EmbedC m b)
-> (forall a b. a -> EmbedC m b -> EmbedC m a)
-> Functor (EmbedC m)
forall a b. a -> EmbedC m b -> EmbedC m a
forall a b. (a -> b) -> EmbedC m a -> EmbedC m b
forall (m :: * -> *) a b.
Functor m =>
a -> EmbedC m b -> EmbedC m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> EmbedC m a -> EmbedC m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> EmbedC m b -> EmbedC m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> EmbedC m b -> EmbedC m a
fmap :: (a -> b) -> EmbedC m a -> EmbedC m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> EmbedC m a -> EmbedC m b
Functor, Functor (EmbedC m)
a -> EmbedC m a
Functor (EmbedC m)
-> (forall a. a -> EmbedC m a)
-> (forall a b. EmbedC m (a -> b) -> EmbedC m a -> EmbedC m b)
-> (forall a b c.
    (a -> b -> c) -> EmbedC m a -> EmbedC m b -> EmbedC m c)
-> (forall a b. EmbedC m a -> EmbedC m b -> EmbedC m b)
-> (forall a b. EmbedC m a -> EmbedC m b -> EmbedC m a)
-> Applicative (EmbedC m)
EmbedC m a -> EmbedC m b -> EmbedC m b
EmbedC m a -> EmbedC m b -> EmbedC m a
EmbedC m (a -> b) -> EmbedC m a -> EmbedC m b
(a -> b -> c) -> EmbedC m a -> EmbedC m b -> EmbedC m c
forall a. a -> EmbedC m a
forall a b. EmbedC m a -> EmbedC m b -> EmbedC m a
forall a b. EmbedC m a -> EmbedC m b -> EmbedC m b
forall a b. EmbedC m (a -> b) -> EmbedC m a -> EmbedC m b
forall a b c.
(a -> b -> c) -> EmbedC m a -> EmbedC m b -> EmbedC 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
forall (m :: * -> *). Applicative m => Functor (EmbedC m)
forall (m :: * -> *) a. Applicative m => a -> EmbedC m a
forall (m :: * -> *) a b.
Applicative m =>
EmbedC m a -> EmbedC m b -> EmbedC m a
forall (m :: * -> *) a b.
Applicative m =>
EmbedC m a -> EmbedC m b -> EmbedC m b
forall (m :: * -> *) a b.
Applicative m =>
EmbedC m (a -> b) -> EmbedC m a -> EmbedC m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> EmbedC m a -> EmbedC m b -> EmbedC m c
<* :: EmbedC m a -> EmbedC m b -> EmbedC m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
EmbedC m a -> EmbedC m b -> EmbedC m a
*> :: EmbedC m a -> EmbedC m b -> EmbedC m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
EmbedC m a -> EmbedC m b -> EmbedC m b
liftA2 :: (a -> b -> c) -> EmbedC m a -> EmbedC m b -> EmbedC m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> EmbedC m a -> EmbedC m b -> EmbedC m c
<*> :: EmbedC m (a -> b) -> EmbedC m a -> EmbedC m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
EmbedC m (a -> b) -> EmbedC m a -> EmbedC m b
pure :: a -> EmbedC m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> EmbedC m a
$cp1Applicative :: forall (m :: * -> *). Applicative m => Functor (EmbedC m)
Applicative, Applicative (EmbedC m)
a -> EmbedC m a
Applicative (EmbedC m)
-> (forall a b. EmbedC m a -> (a -> EmbedC m b) -> EmbedC m b)
-> (forall a b. EmbedC m a -> EmbedC m b -> EmbedC m b)
-> (forall a. a -> EmbedC m a)
-> Monad (EmbedC m)
EmbedC m a -> (a -> EmbedC m b) -> EmbedC m b
EmbedC m a -> EmbedC m b -> EmbedC m b
forall a. a -> EmbedC m a
forall a b. EmbedC m a -> EmbedC m b -> EmbedC m b
forall a b. EmbedC m a -> (a -> EmbedC m b) -> EmbedC m b
forall (m :: * -> *). Monad m => Applicative (EmbedC m)
forall (m :: * -> *) a. Monad m => a -> EmbedC m a
forall (m :: * -> *) a b.
Monad m =>
EmbedC m a -> EmbedC m b -> EmbedC m b
forall (m :: * -> *) a b.
Monad m =>
EmbedC m a -> (a -> EmbedC m b) -> EmbedC 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
return :: a -> EmbedC m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> EmbedC m a
>> :: EmbedC m a -> EmbedC m b -> EmbedC m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
EmbedC m a -> EmbedC m b -> EmbedC m b
>>= :: EmbedC m a -> (a -> EmbedC m b) -> EmbedC m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
EmbedC m a -> (a -> EmbedC m b) -> EmbedC m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (EmbedC m)
Monad
           , Applicative (EmbedC m)
EmbedC m a
Applicative (EmbedC m)
-> (forall a. EmbedC m a)
-> (forall a. EmbedC m a -> EmbedC m a -> EmbedC m a)
-> (forall a. EmbedC m a -> EmbedC m [a])
-> (forall a. EmbedC m a -> EmbedC m [a])
-> Alternative (EmbedC m)
EmbedC m a -> EmbedC m a -> EmbedC m a
EmbedC m a -> EmbedC m [a]
EmbedC m a -> EmbedC m [a]
forall a. EmbedC m a
forall a. EmbedC m a -> EmbedC m [a]
forall a. EmbedC m a -> EmbedC m a -> EmbedC 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 => Applicative (EmbedC m)
forall (m :: * -> *) a. Alternative m => EmbedC m a
forall (m :: * -> *) a. Alternative m => EmbedC m a -> EmbedC m [a]
forall (m :: * -> *) a.
Alternative m =>
EmbedC m a -> EmbedC m a -> EmbedC m a
many :: EmbedC m a -> EmbedC m [a]
$cmany :: forall (m :: * -> *) a. Alternative m => EmbedC m a -> EmbedC m [a]
some :: EmbedC m a -> EmbedC m [a]
$csome :: forall (m :: * -> *) a. Alternative m => EmbedC m a -> EmbedC m [a]
<|> :: EmbedC m a -> EmbedC m a -> EmbedC m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
EmbedC m a -> EmbedC m a -> EmbedC m a
empty :: EmbedC m a
$cempty :: forall (m :: * -> *) a. Alternative m => EmbedC m a
$cp1Alternative :: forall (m :: * -> *). Alternative m => Applicative (EmbedC m)
Alternative, Monad (EmbedC m)
Alternative (EmbedC m)
EmbedC m a
Alternative (EmbedC m)
-> Monad (EmbedC m)
-> (forall a. EmbedC m a)
-> (forall a. EmbedC m a -> EmbedC m a -> EmbedC m a)
-> MonadPlus (EmbedC m)
EmbedC m a -> EmbedC m a -> EmbedC m a
forall a. EmbedC m a
forall a. EmbedC m a -> EmbedC m a -> EmbedC m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
forall (m :: * -> *). MonadPlus m => Monad (EmbedC m)
forall (m :: * -> *). MonadPlus m => Alternative (EmbedC m)
forall (m :: * -> *) a. MonadPlus m => EmbedC m a
forall (m :: * -> *) a.
MonadPlus m =>
EmbedC m a -> EmbedC m a -> EmbedC m a
mplus :: EmbedC m a -> EmbedC m a -> EmbedC m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
EmbedC m a -> EmbedC m a -> EmbedC m a
mzero :: EmbedC m a
$cmzero :: forall (m :: * -> *) a. MonadPlus m => EmbedC m a
$cp2MonadPlus :: forall (m :: * -> *). MonadPlus m => Monad (EmbedC m)
$cp1MonadPlus :: forall (m :: * -> *). MonadPlus m => Alternative (EmbedC m)
MonadPlus
           , Monad (EmbedC m)
Monad (EmbedC m)
-> (forall a. (a -> EmbedC m a) -> EmbedC m a)
-> MonadFix (EmbedC m)
(a -> EmbedC m a) -> EmbedC m a
forall a. (a -> EmbedC m a) -> EmbedC m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
forall (m :: * -> *). MonadFix m => Monad (EmbedC m)
forall (m :: * -> *) a.
MonadFix m =>
(a -> EmbedC m a) -> EmbedC m a
mfix :: (a -> EmbedC m a) -> EmbedC m a
$cmfix :: forall (m :: * -> *) a.
MonadFix m =>
(a -> EmbedC m a) -> EmbedC m a
$cp1MonadFix :: forall (m :: * -> *). MonadFix m => Monad (EmbedC m)
MonadFix, Monad (EmbedC m)
Monad (EmbedC m)
-> (forall a. String -> EmbedC m a) -> MonadFail (EmbedC m)
String -> EmbedC m a
forall a. String -> EmbedC m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
forall (m :: * -> *). MonadFail m => Monad (EmbedC m)
forall (m :: * -> *) a. MonadFail m => String -> EmbedC m a
fail :: String -> EmbedC m a
$cfail :: forall (m :: * -> *) a. MonadFail m => String -> EmbedC m a
$cp1MonadFail :: forall (m :: * -> *). MonadFail m => Monad (EmbedC m)
Fail.MonadFail, Monad (EmbedC m)
Monad (EmbedC m)
-> (forall a. IO a -> EmbedC m a) -> MonadIO (EmbedC m)
IO a -> EmbedC m a
forall a. IO a -> EmbedC m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (EmbedC m)
forall (m :: * -> *) a. MonadIO m => IO a -> EmbedC m a
liftIO :: IO a -> EmbedC m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> EmbedC m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (EmbedC m)
MonadIO
           , Monad (EmbedC m)
e -> EmbedC m a
Monad (EmbedC m)
-> (forall e a. Exception e => e -> EmbedC m a)
-> MonadThrow (EmbedC m)
forall e a. Exception e => e -> EmbedC m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
forall (m :: * -> *). MonadThrow m => Monad (EmbedC m)
forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> EmbedC m a
throwM :: e -> EmbedC m a
$cthrowM :: forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> EmbedC m a
$cp1MonadThrow :: forall (m :: * -> *). MonadThrow m => Monad (EmbedC m)
MonadThrow, MonadThrow (EmbedC m)
MonadThrow (EmbedC m)
-> (forall e a.
    Exception e =>
    EmbedC m a -> (e -> EmbedC m a) -> EmbedC m a)
-> MonadCatch (EmbedC m)
EmbedC m a -> (e -> EmbedC m a) -> EmbedC m a
forall e a.
Exception e =>
EmbedC m a -> (e -> EmbedC m a) -> EmbedC m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
forall (m :: * -> *). MonadCatch m => MonadThrow (EmbedC m)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
EmbedC m a -> (e -> EmbedC m a) -> EmbedC m a
catch :: EmbedC m a -> (e -> EmbedC m a) -> EmbedC m a
$ccatch :: forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
EmbedC m a -> (e -> EmbedC m a) -> EmbedC m a
$cp1MonadCatch :: forall (m :: * -> *). MonadCatch m => MonadThrow (EmbedC m)
MonadCatch, MonadCatch (EmbedC m)
MonadCatch (EmbedC m)
-> (forall b.
    ((forall a. EmbedC m a -> EmbedC m a) -> EmbedC m b) -> EmbedC m b)
-> (forall b.
    ((forall a. EmbedC m a -> EmbedC m a) -> EmbedC m b) -> EmbedC m b)
-> (forall a b c.
    EmbedC m a
    -> (a -> ExitCase b -> EmbedC m c)
    -> (a -> EmbedC m b)
    -> EmbedC m (b, c))
-> MonadMask (EmbedC m)
EmbedC m a
-> (a -> ExitCase b -> EmbedC m c)
-> (a -> EmbedC m b)
-> EmbedC m (b, c)
((forall a. EmbedC m a -> EmbedC m a) -> EmbedC m b) -> EmbedC m b
((forall a. EmbedC m a -> EmbedC m a) -> EmbedC m b) -> EmbedC m b
forall b.
((forall a. EmbedC m a -> EmbedC m a) -> EmbedC m b) -> EmbedC m b
forall a b c.
EmbedC m a
-> (a -> ExitCase b -> EmbedC m c)
-> (a -> EmbedC m b)
-> EmbedC m (b, c)
forall (m :: * -> *).
MonadCatch m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
    m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
forall (m :: * -> *). MonadMask m => MonadCatch (EmbedC m)
forall (m :: * -> *) b.
MonadMask m =>
((forall a. EmbedC m a -> EmbedC m a) -> EmbedC m b) -> EmbedC m b
forall (m :: * -> *) a b c.
MonadMask m =>
EmbedC m a
-> (a -> ExitCase b -> EmbedC m c)
-> (a -> EmbedC m b)
-> EmbedC m (b, c)
generalBracket :: EmbedC m a
-> (a -> ExitCase b -> EmbedC m c)
-> (a -> EmbedC m b)
-> EmbedC m (b, c)
$cgeneralBracket :: forall (m :: * -> *) a b c.
MonadMask m =>
EmbedC m a
-> (a -> ExitCase b -> EmbedC m c)
-> (a -> EmbedC m b)
-> EmbedC m (b, c)
uninterruptibleMask :: ((forall a. EmbedC m a -> EmbedC m a) -> EmbedC m b) -> EmbedC m b
$cuninterruptibleMask :: forall (m :: * -> *) b.
MonadMask m =>
((forall a. EmbedC m a -> EmbedC m a) -> EmbedC m b) -> EmbedC m b
mask :: ((forall a. EmbedC m a -> EmbedC m a) -> EmbedC m b) -> EmbedC m b
$cmask :: forall (m :: * -> *) b.
MonadMask m =>
((forall a. EmbedC m a -> EmbedC m a) -> EmbedC m b) -> EmbedC m b
$cp1MonadMask :: forall (m :: * -> *). MonadMask m => MonadCatch (EmbedC m)
MonadMask
           , MonadBase b, MonadBaseControl b
           )
  deriving (m a -> EmbedC m a
(forall (m :: * -> *) a. Monad m => m a -> EmbedC m a)
-> MonadTrans EmbedC
forall (m :: * -> *) a. Monad m => m a -> EmbedC m a
forall (t :: Effect).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> EmbedC m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> EmbedC m a
MonadTrans, MonadTrans EmbedC
m (StT EmbedC a) -> EmbedC m a
MonadTrans EmbedC
-> (forall (m :: * -> *) a.
    Monad m =>
    (Run EmbedC -> m a) -> EmbedC m a)
-> (forall (m :: * -> *) a.
    Monad m =>
    m (StT EmbedC a) -> EmbedC m a)
-> MonadTransControl EmbedC
(Run EmbedC -> m a) -> EmbedC m a
forall (m :: * -> *) a. Monad m => m (StT EmbedC a) -> EmbedC m a
forall (m :: * -> *) a.
Monad m =>
(Run EmbedC -> m a) -> EmbedC m a
forall (t :: Effect).
MonadTrans t
-> (forall (m :: * -> *) a. Monad m => (Run t -> m a) -> t m a)
-> (forall (m :: * -> *) a. Monad m => m (StT t a) -> t m a)
-> MonadTransControl t
restoreT :: m (StT EmbedC a) -> EmbedC m a
$crestoreT :: forall (m :: * -> *) a. Monad m => m (StT EmbedC a) -> EmbedC m a
liftWith :: (Run EmbedC -> m a) -> EmbedC m a
$cliftWith :: forall (m :: * -> *) a.
Monad m =>
(Run EmbedC -> m a) -> EmbedC m a
$cp1MonadTransControl :: MonadTrans EmbedC
MonadTransControl) via IdentityT

-- | Run an @'Embed' m@ effect, where the embedded monad @m@ is the current monad.
--
-- Not to be confused with 'runM'. This is simply an interpreter for @'Embed' m@;
-- it doesn't extract the final monad.
--
-- @'Derivs' ('EmbedC' m) = 'Embed' m ': 'Derivs' m@
--
-- @'Prims'  ('EmbedC' m) = 'Prims' m@
--
-- @since 0.1.1.0
runEmbed :: Carrier m => EmbedC m a -> m a
runEmbed :: EmbedC m a -> m a
runEmbed = EmbedC m a -> m a
forall k (m :: k -> *) (a :: k). EmbedC m a -> m a
unEmbedC
{-# INLINE runEmbed #-}

instance Carrier m => Carrier (EmbedC m) where
  type Derivs (EmbedC m) = Embed m ': Derivs m
  type Prims  (EmbedC m) = Prims m

  algPrims :: Algebra' (Prims (EmbedC m)) (EmbedC m) a
algPrims = (Union (Prims m) m a -> m a) -> Algebra' (Prims m) (EmbedC m) a
coerce (forall a. Carrier m => Algebra' (Prims m) m a
forall (m :: * -> *) a. Carrier m => Algebra' (Prims m) m a
algPrims @m)
  {-# INLINEABLE algPrims #-}

  reformulate :: Reformulation'
  (Derivs (EmbedC m)) (Prims (EmbedC m)) (EmbedC m) z a
reformulate forall x. EmbedC m x -> z x
n Algebra (Prims (EmbedC m)) z
alg = Algebra' (Derivs m) z a
-> (Embed m z a -> z a) -> Algebra' (Embed m : Derivs m) z a
forall (e :: Effect) (r :: [Effect]) (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg (Reformulation' (Derivs m) (Prims m) m z a
forall (m :: * -> *) (z :: * -> *) a.
(Carrier m, Monad z) =>
Reformulation' (Derivs m) (Prims m) m z a
reformulate (EmbedC m x -> z x
forall x. EmbedC m x -> z x
n (EmbedC m x -> z x) -> (m x -> EmbedC m x) -> m x -> z x
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# m x -> EmbedC m x
forall k (m :: k -> *) (a :: k). m a -> EmbedC m a
EmbedC) forall x. Union (Prims m) z x -> z x
Algebra (Prims (EmbedC m)) z
alg) (EmbedC m a -> z a
forall x. EmbedC m x -> z x
n (EmbedC m a -> z a) -> (m a -> EmbedC m a) -> m a -> z a
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# m a -> EmbedC m a
forall k (m :: k -> *) (a :: k). m a -> EmbedC m a
EmbedC (m a -> z a) -> (Embed m z a -> m a) -> Embed m z a -> z a
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# Embed m z a -> m a
forall k (b :: k -> *) (m :: * -> *) (a :: k). Embed b m a -> b a
unEmbed)
  {-# INLINEABLE reformulate #-}

  algDerivs :: Algebra' (Derivs (EmbedC m)) (EmbedC m) a
algDerivs = Algebra' (Derivs m) (EmbedC m) a
-> (Embed m (EmbedC m) a -> EmbedC m a)
-> Algebra' (Embed m : Derivs m) (EmbedC m) a
forall (e :: Effect) (r :: [Effect]) (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg (Algebra' (Derivs m) m a -> Algebra' (Derivs m) (EmbedC m) a
coerce (forall a. Carrier m => Algebra' (Derivs m) m a
forall (m :: * -> *) a. Carrier m => Algebra' (Derivs m) m a
algDerivs @m)) (m a -> EmbedC m a
forall k (m :: k -> *) (a :: k). m a -> EmbedC m a
EmbedC (m a -> EmbedC m a)
-> (Embed m (EmbedC m) a -> m a)
-> Embed m (EmbedC m) a
-> EmbedC m a
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# Embed m (EmbedC m) a -> m a
forall k (b :: k -> *) (m :: * -> *) (a :: k). Embed b m a -> b a
unEmbed)
  {-# INLINEABLE algDerivs #-}

-- | Extract the final monad @m@ from a computation of which
-- no effects remain to be handled except for @'Embed' m@.
runM :: Monad m => RunMC m a -> m a
runM :: RunMC m a -> m a
runM = RunMC m a -> m a
forall k (m :: k -> *) (a :: k). RunMC m a -> m a
unRunMC
{-# INLINE runM #-}

data EmbedToMonadBaseH
data EmbedToMonadIOH

instance ( MonadBase b m
         , Carrier m
         )
      => Handler EmbedToMonadBaseH (Embed b) m where
  effHandler :: Embed b (Effly z) x -> Effly z x
effHandler = m x -> Effly z x
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (m x -> Effly z x) -> (b x -> m x) -> b x -> Effly z x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b x -> m x
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (b x -> Effly z x)
-> (Embed b (Effly z) x -> b x) -> Embed b (Effly z) x -> Effly z x
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# Embed b (Effly z) x -> b x
forall k (b :: k -> *) (m :: * -> *) (a :: k). Embed b m a -> b a
unEmbed
  {-# INLINEABLE effHandler #-}

instance (MonadIO m, Carrier m) => Handler EmbedToMonadIOH (Embed IO) m where
  effHandler :: Embed IO (Effly z) x -> Effly z x
effHandler = m x -> Effly z x
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (m x -> Effly z x) -> (IO x -> m x) -> IO x -> Effly z x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO x -> m x
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO x -> Effly z x)
-> (Embed IO (Effly z) x -> IO x)
-> Embed IO (Effly z) x
-> Effly z x
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# Embed IO (Effly z) x -> IO x
forall k (b :: k -> *) (m :: * -> *) (a :: k). Embed b m a -> b a
unEmbed
  {-# INLINEABLE effHandler #-}

type EmbedToMonadBaseC b = InterpretC EmbedToMonadBaseH (Embed b)
type EmbedToMonadIOC = InterpretC EmbedToMonadIOH (Embed IO)

-- | Transform an 'Embed' effect into another 'Embed' effect
-- by providing a natural transformation to convert monadic values
-- of one monad to the other.
--
-- This has a higher-rank type, as it makes use of 'InterpretReifiedC'.
-- __This makes 'embedToEmbed' very difficult to use partially applied.__
-- __In particular, it can't be composed using @'.'@.__
--
-- If performance is secondary, consider using the slower
-- 'embedToEmbedSimple', which doesn't have a higher-rank type.
embedToEmbed :: forall b b' m a
              . Eff (Embed b') m
             => (forall x. b x -> b' x)
             -> InterpretReifiedC (Embed b) m a
             -> m a
embedToEmbed :: (forall x. b x -> b' x) -> InterpretReifiedC (Embed b) m a -> m a
embedToEmbed forall x. b x -> b' x
n = EffHandler (Embed b) m -> InterpretReifiedC (Embed b) m a -> m a
forall (e :: Effect) (m :: * -> *) a.
(RepresentationalEff e, Carrier m) =>
EffHandler e m -> InterpretReifiedC e m a -> m a
interpret (EffHandler (Embed b) m -> InterpretReifiedC (Embed b) m a -> m a)
-> EffHandler (Embed b) m -> InterpretReifiedC (Embed b) m a -> m a
forall a b. (a -> b) -> a -> b
$ \case
  Embed m -> b' x -> Effly z x
forall (b :: * -> *) (m :: * -> *) a. Eff (Embed b) m => b a -> m a
embed (b x -> b' x
forall x. b x -> b' x
n b x
m)
{-# INLINE embedToEmbed #-}

-- | Run an @'Embed' b@ effect if @b@ is the base of the current
-- monad @m@.
embedToMonadBase :: (MonadBase b m, Carrier m)
                 => EmbedToMonadBaseC b m a
                 -> m a
embedToMonadBase :: EmbedToMonadBaseC b m a -> m a
embedToMonadBase = EmbedToMonadBaseC b m a -> m a
forall h (e :: Effect) (m :: * -> *) a.
Handler h e m =>
InterpretC h e m a -> m a
interpretViaHandler
{-# INLINE embedToMonadBase #-}

-- | Run an @'Embed' IO@ effect if the current monad @m@ is a @MonadIO@.
embedToMonadIO :: (MonadIO m, Carrier m)
               => EmbedToMonadIOC m a
               -> m a
embedToMonadIO :: EmbedToMonadIOC m a -> m a
embedToMonadIO = EmbedToMonadIOC m a -> m a
forall h (e :: Effect) (m :: * -> *) a.
Handler h e m =>
InterpretC h e m a -> m a
interpretViaHandler
{-# INLINE embedToMonadIO #-}

-- | Transform an 'Embed' effect into another 'Embed' effect
-- by providing a natural transformation to convert monadic values
-- of one monad to the other.
--
-- This is a less performant version of 'embedToEmbed' that doesn't have
-- a higher-rank type, making it much easier to use partially applied.
embedToEmbedSimple :: forall b b' m a p
                    . ( Eff (Embed b') m
                      , Threaders '[ReaderThreads] m p
                      )
                   => (forall x. b x -> b' x)
                   -> InterpretSimpleC (Embed b) m a
                   -> m a
embedToEmbedSimple :: (forall x. b x -> b' x) -> InterpretSimpleC (Embed b) m a -> m a
embedToEmbedSimple forall x. b x -> b' x
n = EffHandler (Embed b) m -> InterpretSimpleC (Embed b) m a -> m a
forall (e :: Effect) (m :: * -> *) a (p :: [Effect]).
(RepresentationalEff e, Threaders '[ReaderThreads] m p,
 Carrier m) =>
EffHandler e m -> InterpretSimpleC e m a -> m a
interpretSimple (EffHandler (Embed b) m -> InterpretSimpleC (Embed b) m a -> m a)
-> EffHandler (Embed b) m -> InterpretSimpleC (Embed b) m a -> m a
forall a b. (a -> b) -> a -> b
$ \case
  Embed m -> b' x -> Effly z x
forall (b :: * -> *) (m :: * -> *) a. Eff (Embed b) m => b a -> m a
embed (b x -> b' x
forall x. b x -> b' x
n b x
m)
{-# INLINE embedToEmbedSimple #-}