{-# LANGUAGE AllowAmbiguousTypes, Trustworthy #-}
module Polysemy.Shift
  (
    module Polysemy.Cont
    -- * Effect
  , Shift(..)

    -- * Actions
  , trap
  , invoke
  , abort
  , reset
  , reset'
  , shift

    -- * Interpretations
  , runShiftPure
  , runShiftM
  , shiftToFinal
  , runShiftWithCPure
  , runShiftWithCM

  , runContShiftPure
  , runContShiftM
  , runContShiftWithCPure
  , runContShiftWithCM

    -- * Unsafe Interpretations
  , runShiftUnsafe
  , runShiftWithCUnsafe
  , runContShiftUnsafe
  , runContShiftWithCUnsafe
  ) where


import Polysemy
import Polysemy.Cont
import Polysemy.Cont.Internal
import Polysemy.Shift.Internal
import Polysemy.Final
import Control.Monad.Cont (ContT(..))

import Polysemy.Internal
import Polysemy.Internal.Union


-----------------------------------------------------------------------------
-- | A variant of 'callCC'.
-- Executing the provided continuation will not abort execution.
--
-- Any effectful state of effects which have been run before the interpreter for
-- 'Shift' will be embedded in the return value of the continuation,
-- and therefore the continuation won't have any apparent effects unless these
-- effects are interpreted in the final monad.
--
-- Any higher-order actions will also not interact with the continuation in any
-- meaningful way; i.e. 'Polysemy.Reader.local' or 'Polysemy.Writer.censor' does
-- not affect it, 'Polysemy.Error.catch' will fail to catch any of its exceptions,
-- and 'Polysemy.Writer.listen' will always return 'mempty'.
--
-- The provided continuation may fail locally in its subcontinuations.
-- It may sometimes become necessary to handle such cases, in
-- which case such failure may be detected by using 'reset\'' together
-- with the provided continuation.
shift :: forall ref s r a
       . Member (Shift ref s) r
      => ((a -> Sem r s) -> Sem r s)
      -> Sem r a
shift :: ((a -> Sem r s) -> Sem r s) -> Sem r a
shift (a -> Sem r s) -> Sem r s
cc = forall s a (r :: EffectRow).
Member (Shift ref s) r =>
(ref a -> Sem r s) -> Sem r a
forall (ref :: * -> *) s a (r :: EffectRow).
Member (Shift ref s) r =>
(ref a -> Sem r s) -> Sem r a
trap @ref ((ref a -> Sem r s) -> Sem r a) -> (ref a -> Sem r s) -> Sem r a
forall a b. (a -> b) -> a -> b
$ \ref a
ref -> (a -> Sem r s) -> Sem r s
cc (ref a -> a -> Sem r s
forall (ref :: * -> *) s a (r :: EffectRow).
Member (Shift ref s) r =>
ref a -> a -> Sem r s
invoke ref a
ref)
{-# INLINE shift #-}

-----------------------------------------------------------------------------
-- | Runs a 'Shift' effect by providing @'pure' '.' 'Just'@ as the final
-- continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that
-- any continuation may fail locally.
--
-- This is a safe variant of 'runShiftUnsafe', as this may only be used
-- as the final interpreter before 'run'.
runShiftPure :: Sem '[Shift (Ref (Sem '[]) (Maybe a)) a] a
             -> Sem '[] (Maybe a)
runShiftPure :: Sem '[Shift (Ref (Sem '[]) (Maybe a)) a] a -> Sem '[] (Maybe a)
runShiftPure = Sem '[Shift (Ref (Sem '[]) (Maybe a)) a] a -> Sem '[] (Maybe a)
forall (r :: EffectRow) a.
Sem (Shift (Ref (Sem r) (Maybe a)) a : r) a -> Sem r (Maybe a)
runShiftUnsafe
{-# INLINE runShiftPure #-}

-----------------------------------------------------------------------------
-- | Runs a 'Shift' effect by providing @'pure' '.' 'Just'@ as the final
-- continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that
-- any continuation may fail locally.
--
-- This is a safe variant of 'runShiftUnsafe', as this may only be used
-- as the final interpreter before 'runM'.
runShiftM :: Sem '[Shift (Ref (Sem '[Embed m]) (Maybe a)) a, Embed m] a
          -> Sem '[Embed m] (Maybe a)
runShiftM :: Sem '[Shift (Ref (Sem '[Embed m]) (Maybe a)) a, Embed m] a
-> Sem '[Embed m] (Maybe a)
runShiftM = Sem '[Shift (Ref (Sem '[Embed m]) (Maybe a)) a, Embed m] a
-> Sem '[Embed m] (Maybe a)
forall (r :: EffectRow) a.
Sem (Shift (Ref (Sem r) (Maybe a)) a : r) a -> Sem r (Maybe a)
runShiftUnsafe
{-# INLINE runShiftM #-}

-----------------------------------------------------------------------------
-- | Runs a 'Shift' effect in terms of a final 'ContT'
--
-- /Beware/: Effects that aren't interpreted in terms of the final monad
-- will have local state semantics in regards to 'Shift' effects
-- interpreted this way. See 'Final'.
shiftToFinal :: forall s m a r
              .  (Member (Final (ContT (Maybe s) m)) r, Monad m)
              => Sem (Shift (Ref m (Maybe s)) s ': r) a
              -> Sem r a
shiftToFinal :: Sem (Shift (Ref m (Maybe s)) s : r) a -> Sem r a
shiftToFinal = (forall x (rInitial :: EffectRow).
 Shift (Ref m (Maybe s)) s (Sem rInitial) x
 -> Strategic (ContT (Maybe s) m) (Sem rInitial) x)
-> Sem (Shift (Ref m (Maybe s)) s : r) a -> Sem r a
forall (m :: * -> *) (e :: (* -> *) -> * -> *) (r :: EffectRow) a.
Member (Final m) r =>
(forall x (rInitial :: EffectRow).
 e (Sem rInitial) x -> Strategic m (Sem rInitial) x)
-> Sem (e : r) a -> Sem r a
interpretFinal ((forall x (rInitial :: EffectRow).
  Shift (Ref m (Maybe s)) s (Sem rInitial) x
  -> Strategic (ContT (Maybe s) m) (Sem rInitial) x)
 -> Sem (Shift (Ref m (Maybe s)) s : r) a -> Sem r a)
-> (forall x (rInitial :: EffectRow).
    Shift (Ref m (Maybe s)) s (Sem rInitial) x
    -> Strategic (ContT (Maybe s) m) (Sem rInitial) x)
-> Sem (Shift (Ref m (Maybe s)) s : r) a
-> Sem r a
forall a b. (a -> b) -> a -> b
$ \case
  Trap main -> do
    f (Ref m (Maybe s) x) -> ContT (Maybe s) m (f s)
main'         <- (Ref m (Maybe s) x -> Sem rInitial s)
-> Sem
     (WithStrategy (ContT (Maybe s) m) f (Sem rInitial))
     (f (Ref m (Maybe s) x) -> ContT (Maybe s) m (f s))
forall a (n :: * -> *) b (m :: * -> *) (f :: * -> *).
(a -> n b) -> Sem (WithStrategy m f n) (f a -> m (f b))
bindS Ref m (Maybe s) x -> Sem rInitial s
main
    f ()
s             <- Sem (WithStrategy (ContT (Maybe s) m) f (Sem rInitial)) (f ())
forall (m :: * -> *) (f :: * -> *) (n :: * -> *).
Sem (WithStrategy m f n) (f ())
getInitialStateS
    Inspector forall x. f x -> Maybe x
ins <- Sem
  (WithStrategy (ContT (Maybe s) m) f (Sem rInitial)) (Inspector f)
forall (m :: * -> *) (f :: * -> *) (n :: * -> *).
Sem (WithStrategy m f n) (Inspector f)
getInspectorS
    ContT (Maybe s) m (f x)
-> Sem
     (WithStrategy (ContT (Maybe s) m) f (Sem rInitial))
     (ContT (Maybe s) m (f x))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ContT (Maybe s) m (f x)
 -> Sem
      (WithStrategy (ContT (Maybe s) m) f (Sem rInitial))
      (ContT (Maybe s) m (f x)))
-> ContT (Maybe s) m (f x)
-> Sem
     (WithStrategy (ContT (Maybe s) m) f (Sem rInitial))
     (ContT (Maybe s) m (f x))
forall a b. (a -> b) -> a -> b
$ ((f x -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m (f x)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((f x -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m (f x))
-> ((f x -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m (f x)
forall a b. (a -> b) -> a -> b
$ \f x -> m (Maybe s)
c ->
      ContT (Maybe s) m (f s) -> (f s -> m (Maybe s)) -> m (Maybe s)
forall k (r :: k) (m :: k -> *) a. ContT r m a -> (a -> m r) -> m r
runContT (f (Ref m (Maybe s) x) -> ContT (Maybe s) m (f s)
main' ((x -> m (Maybe s)) -> Ref m (Maybe s) x
forall k (m :: k -> *) (s :: k) a. (a -> m s) -> Ref m s a
Ref (f x -> m (Maybe s)
c (f x -> m (Maybe s)) -> (x -> f x) -> x -> m (Maybe s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (x -> f () -> f x
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ f ()
s)) Ref m (Maybe s) x -> f () -> f (Ref m (Maybe s) x)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ f ()
s)) (Maybe s -> m (Maybe s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe s -> m (Maybe s)) -> (f s -> Maybe s) -> f s -> m (Maybe s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f s -> Maybe s
forall x. f x -> Maybe x
ins)
  Invoke ref a -> ContT (Maybe s) m x
-> Strategic (ContT (Maybe s) m) (Sem rInitial) x
forall (m :: * -> *) a (n :: * -> *).
Functor m =>
m a -> Strategic m n a
liftS (ContT (Maybe s) m x
 -> Strategic (ContT (Maybe s) m) (Sem rInitial) x)
-> ContT (Maybe s) m x
-> Strategic (ContT (Maybe s) m) (Sem rInitial) x
forall a b. (a -> b) -> a -> b
$ ((x -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m x
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((x -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m x)
-> ((x -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m x
forall a b. (a -> b) -> a -> b
$ \x -> m (Maybe s)
c -> Ref m (Maybe x) a -> a -> m (Maybe x)
forall k (m :: k -> *) (s :: k) a. Ref m s a -> a -> m s
runRef Ref m (Maybe s) a
Ref m (Maybe x) a
ref a
a m (Maybe x) -> (Maybe x -> m (Maybe s)) -> m (Maybe s)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= m (Maybe s) -> (x -> m (Maybe s)) -> Maybe x -> m (Maybe s)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe s -> m (Maybe s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe s
forall a. Maybe a
Nothing) x -> m (Maybe s)
c
  Abort s -> ContT (Maybe s) m (f x)
-> Sem
     (WithStrategy (ContT (Maybe s) m) f (Sem rInitial))
     (ContT (Maybe s) m (f x))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ContT (Maybe s) m (f x)
 -> Sem
      (WithStrategy (ContT (Maybe s) m) f (Sem rInitial))
      (ContT (Maybe s) m (f x)))
-> ContT (Maybe s) m (f x)
-> Sem
     (WithStrategy (ContT (Maybe s) m) f (Sem rInitial))
     (ContT (Maybe s) m (f x))
forall a b. (a -> b) -> a -> b
$ ((f x -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m (f x)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((f x -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m (f x))
-> ((f x -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m (f x)
forall a b. (a -> b) -> a -> b
$ \f x -> m (Maybe s)
_ -> Maybe s -> m (Maybe s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (s -> Maybe s
forall a. a -> Maybe a
Just s
s)
  Reset main -> do
    ContT (Maybe s) m (f s)
main'         <- Sem rInitial s
-> Sem
     (WithStrategy (ContT (Maybe s) m) f (Sem rInitial))
     (ContT (Maybe s) m (f s))
forall (n :: * -> *) a (m :: * -> *) (f :: * -> *).
n a -> Sem (WithStrategy m f n) (m (f a))
runS Sem rInitial s
main
    Inspector forall x. f x -> Maybe x
ins <- Sem
  (WithStrategy (ContT (Maybe s) m) f (Sem rInitial)) (Inspector f)
forall (m :: * -> *) (f :: * -> *) (n :: * -> *).
Sem (WithStrategy m f n) (Inspector f)
getInspectorS
    ContT (Maybe s) m s
-> Strategic (ContT (Maybe s) m) (Sem rInitial) s
forall (m :: * -> *) a (n :: * -> *).
Functor m =>
m a -> Strategic m n a
liftS (ContT (Maybe s) m s
 -> Strategic (ContT (Maybe s) m) (Sem rInitial) s)
-> ContT (Maybe s) m s
-> Strategic (ContT (Maybe s) m) (Sem rInitial) s
forall a b. (a -> b) -> a -> b
$ ((s -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m s
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((s -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m s)
-> ((s -> m (Maybe s)) -> m (Maybe s)) -> ContT (Maybe s) m s
forall a b. (a -> b) -> a -> b
$ \s -> m (Maybe s)
c ->
      ContT (Maybe s) m (f s) -> (f s -> m (Maybe s)) -> m (Maybe s)
forall k (r :: k) (m :: k -> *) a. ContT r m a -> (a -> m r) -> m r
runContT ContT (Maybe s) m (f s)
main' (Maybe s -> m (Maybe s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe s -> m (Maybe s)) -> (f s -> Maybe s) -> f s -> m (Maybe s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f s -> Maybe s
forall x. f x -> Maybe x
ins) m (Maybe s) -> (Maybe s -> m (Maybe s)) -> m (Maybe s)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= m (Maybe s) -> (s -> m (Maybe s)) -> Maybe s -> m (Maybe s)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe s -> m (Maybe s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe s
forall a. Maybe a
Nothing) s -> m (Maybe s)
c
  Reset' main -> do
    ContT (Maybe s) m (f s)
main'         <- Sem rInitial s
-> Sem
     (WithStrategy (ContT (Maybe s) m) f (Sem rInitial))
     (ContT (Maybe s) m (f s))
forall (n :: * -> *) a (m :: * -> *) (f :: * -> *).
n a -> Sem (WithStrategy m f n) (m (f a))
runS Sem rInitial s
main
    Inspector forall x. f x -> Maybe x
ins <- Sem
  (WithStrategy (ContT (Maybe s) m) f (Sem rInitial)) (Inspector f)
forall (m :: * -> *) (f :: * -> *) (n :: * -> *).
Sem (WithStrategy m f n) (Inspector f)
getInspectorS
    ContT (Maybe s) m (Maybe s)
-> Strategic (ContT (Maybe s) m) (Sem rInitial) (Maybe s)
forall (m :: * -> *) a (n :: * -> *).
Functor m =>
m a -> Strategic m n a
liftS (ContT (Maybe s) m (Maybe s)
 -> Strategic (ContT (Maybe s) m) (Sem rInitial) (Maybe s))
-> ContT (Maybe s) m (Maybe s)
-> Strategic (ContT (Maybe s) m) (Sem rInitial) (Maybe s)
forall a b. (a -> b) -> a -> b
$ ((Maybe s -> m (Maybe s)) -> m (Maybe s))
-> ContT (Maybe s) m (Maybe s)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Maybe s -> m (Maybe s)) -> m (Maybe s))
 -> ContT (Maybe s) m (Maybe s))
-> ((Maybe s -> m (Maybe s)) -> m (Maybe s))
-> ContT (Maybe s) m (Maybe s)
forall a b. (a -> b) -> a -> b
$ \Maybe s -> m (Maybe s)
c ->
      ContT (Maybe s) m (f s) -> (f s -> m (Maybe s)) -> m (Maybe s)
forall k (r :: k) (m :: k -> *) a. ContT r m a -> (a -> m r) -> m r
runContT ContT (Maybe s) m (f s)
main' (Maybe s -> m (Maybe s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe s -> m (Maybe s)) -> (f s -> Maybe s) -> f s -> m (Maybe s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f s -> Maybe s
forall x. f x -> Maybe x
ins) m (Maybe s) -> (Maybe s -> m (Maybe s)) -> m (Maybe s)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Maybe s -> m (Maybe s)
c
{-# INLINE shiftToFinal #-}

-----------------------------------------------------------------------------
-- | Runs a 'Shift' effect by explicitly providing a final
-- continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that
-- any continuation may fail locally.
--
-- This is a safe variant of 'runShiftWithCUnsafe', as this may only be used
-- as the final interpreter before 'run'.
runShiftWithCPure :: (a -> Sem '[] (Maybe b))
                  -> Sem '[Shift (Ref (Sem '[]) (Maybe b)) b] a
                  -> Sem '[] (Maybe b)
runShiftWithCPure :: (a -> Sem '[] (Maybe b))
-> Sem '[Shift (Ref (Sem '[]) (Maybe b)) b] a -> Sem '[] (Maybe b)
runShiftWithCPure = (a -> Sem '[] (Maybe b))
-> Sem '[Shift (Ref (Sem '[]) (Maybe b)) b] a -> Sem '[] (Maybe b)
forall s a (r :: EffectRow).
(a -> Sem r (Maybe s))
-> Sem (Shift (Ref (Sem r) (Maybe s)) s : r) a -> Sem r (Maybe s)
runShiftWithCUnsafe
{-# INLINE runShiftWithCPure #-}

-----------------------------------------------------------------------------
-- | Runs a 'Shift' effect by explicitly providing a final
-- continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that
-- any continuation may fail locally.
--
-- This is a safe variant of 'runShiftWithCUnsafe', as this may only be used
-- as the final interpreter before 'runM'.
runShiftWithCM :: (a -> Sem '[Embed m] (Maybe b))
               -> Sem '[Shift (Ref (Sem '[Embed m]) (Maybe b)) b, Embed m] a
               -> Sem '[Embed m] (Maybe b)
runShiftWithCM :: (a -> Sem '[Embed m] (Maybe b))
-> Sem '[Shift (Ref (Sem '[Embed m]) (Maybe b)) b, Embed m] a
-> Sem '[Embed m] (Maybe b)
runShiftWithCM = (a -> Sem '[Embed m] (Maybe b))
-> Sem '[Shift (Ref (Sem '[Embed m]) (Maybe b)) b, Embed m] a
-> Sem '[Embed m] (Maybe b)
forall s a (r :: EffectRow).
(a -> Sem r (Maybe s))
-> Sem (Shift (Ref (Sem r) (Maybe s)) s : r) a -> Sem r (Maybe s)
runShiftWithCUnsafe
{-# INLINE runShiftWithCM #-}

-----------------------------------------------------------------------------
-- | Runs a 'Cont' and a 'Shift' effect simultaneously by providing
-- @'pure' '.' 'Just'@ as the final continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that
-- any continuation may fail locally.
--
-- This is a safe variant of 'runContShiftUnsafe', as this may only be used
-- as the final interpreter before 'run'.
runContShiftPure :: Sem [ Cont (Ref (Sem '[]) (Maybe a))
                        , Shift (Ref (Sem '[]) (Maybe a)) a
                        ] a
                 -> Sem '[] (Maybe a)
runContShiftPure :: Sem
  '[Cont (Ref (Sem '[]) (Maybe a)),
    Shift (Ref (Sem '[]) (Maybe a)) a]
  a
-> Sem '[] (Maybe a)
runContShiftPure = Sem
  '[Cont (Ref (Sem '[]) (Maybe a)),
    Shift (Ref (Sem '[]) (Maybe a)) a]
  a
-> Sem '[] (Maybe a)
forall (r :: EffectRow) a.
Sem
  (Cont (Ref (Sem r) (Maybe a))
     : Shift (Ref (Sem r) (Maybe a)) a : r)
  a
-> Sem r (Maybe a)
runContShiftUnsafe
{-# INLINE runContShiftPure #-}

-----------------------------------------------------------------------------
-- | Runs a 'Cont' and a 'Shift' effect simultaneously by providing
-- @'pure' '.' 'Just'@ as the final continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that
-- any continuation may fail locally.
--
-- This is a safe variant of 'runContShiftUnsafe', as this may only be used
-- as the final interpreter before 'runM'.
runContShiftM :: Sem [ Cont (Ref (Sem '[Embed m]) (Maybe a))
                     , Shift (Ref (Sem '[Embed m]) (Maybe a)) a
                     , Embed m
                     ] a
              -> Sem '[Embed m] (Maybe a)
runContShiftM :: Sem
  '[Cont (Ref (Sem '[Embed m]) (Maybe a)),
    Shift (Ref (Sem '[Embed m]) (Maybe a)) a, Embed m]
  a
-> Sem '[Embed m] (Maybe a)
runContShiftM = Sem
  '[Cont (Ref (Sem '[Embed m]) (Maybe a)),
    Shift (Ref (Sem '[Embed m]) (Maybe a)) a, Embed m]
  a
-> Sem '[Embed m] (Maybe a)
forall (r :: EffectRow) a.
Sem
  (Cont (Ref (Sem r) (Maybe a))
     : Shift (Ref (Sem r) (Maybe a)) a : r)
  a
-> Sem r (Maybe a)
runContShiftUnsafe
{-# INLINE runContShiftM #-}

-----------------------------------------------------------------------------
-- | Runs a 'Cont' and a 'Shift' effect simultaneously by explicitly providing
-- a final continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that
-- any continuation may fail locally.
--
-- This is a safe variant of 'runContShiftWithCUnsafe', as this may only be
-- used as the final interpreter before 'run'.
runContShiftWithCPure :: (a -> Sem '[] (Maybe s))
                      -> Sem [ Cont (Ref (Sem '[]) (Maybe s))
                             , Shift (Ref (Sem '[]) (Maybe s)) s
                             ] a
                      -> Sem '[] (Maybe s)
runContShiftWithCPure :: (a -> Sem '[] (Maybe s))
-> Sem
     '[Cont (Ref (Sem '[]) (Maybe s)),
       Shift (Ref (Sem '[]) (Maybe s)) s]
     a
-> Sem '[] (Maybe s)
runContShiftWithCPure = (a -> Sem '[] (Maybe s))
-> Sem
     '[Cont (Ref (Sem '[]) (Maybe s)),
       Shift (Ref (Sem '[]) (Maybe s)) s]
     a
-> Sem '[] (Maybe s)
forall s a (r :: EffectRow).
(a -> Sem r (Maybe s))
-> Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r)
     a
-> Sem r (Maybe s)
runContShiftWithCUnsafe
{-# INLINE runContShiftWithCPure #-}

-----------------------------------------------------------------------------
-- | Runs a 'Cont' and a 'Shift' effect simultaneously by explicitly providing
-- a final continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that
-- any continuation may fail locally.
--
-- This is a safe variant of 'runContShiftWithCUnsafe', as this may only be used
-- as the final interpreter before 'runM'.
runContShiftWithCM :: (a -> Sem '[Embed m] (Maybe s))
                   -> Sem [ Cont (Ref (Sem '[Embed m]) (Maybe s))
                          , Shift (Ref (Sem '[Embed m]) (Maybe s)) s
                          , Embed m
                          ] a
                   -> Sem '[Embed m] (Maybe s)
runContShiftWithCM :: (a -> Sem '[Embed m] (Maybe s))
-> Sem
     '[Cont (Ref (Sem '[Embed m]) (Maybe s)),
       Shift (Ref (Sem '[Embed m]) (Maybe s)) s, Embed m]
     a
-> Sem '[Embed m] (Maybe s)
runContShiftWithCM = (a -> Sem '[Embed m] (Maybe s))
-> Sem
     '[Cont (Ref (Sem '[Embed m]) (Maybe s)),
       Shift (Ref (Sem '[Embed m]) (Maybe s)) s, Embed m]
     a
-> Sem '[Embed m] (Maybe s)
forall s a (r :: EffectRow).
(a -> Sem r (Maybe s))
-> Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r)
     a
-> Sem r (Maybe s)
runContShiftWithCUnsafe
{-# INLINE runContShiftWithCM #-}


-----------------------------------------------------------------------------
-- | Runs a 'Shift' effect by providing @'pure' '.' 'Just'@
-- as the final continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that
-- any continuation may fail locally.
--
-- __Beware__: This interpreter will invalidate all higher-order effects of any
-- interpreter run after it; i.e. 'Polysemy.Reader.local' and
-- 'Polysemy.Writer.censor' will be no-ops, 'Polysemy.Error.catch' will fail
-- to catch exceptions, and 'Polysemy.Writer.listen' will always return 'mempty'.
--
-- __You should therefore use 'runShiftUnsafe' /after/ running all__
-- __interpreters for your higher-order effects.__
runShiftUnsafe :: Sem (Shift (Ref (Sem r) (Maybe a)) a ': r) a -> Sem r (Maybe a)
runShiftUnsafe :: Sem (Shift (Ref (Sem r) (Maybe a)) a : r) a -> Sem r (Maybe a)
runShiftUnsafe = (a -> Sem r (Maybe a))
-> Sem (Shift (Ref (Sem r) (Maybe a)) a : r) a -> Sem r (Maybe a)
forall s a (r :: EffectRow).
(a -> Sem r (Maybe s))
-> Sem (Shift (Ref (Sem r) (Maybe s)) s : r) a -> Sem r (Maybe s)
runShiftWithCUnsafe (Maybe a -> Sem r (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe a -> Sem r (Maybe a))
-> (a -> Maybe a) -> a -> Sem r (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe a
forall a. a -> Maybe a
Just)
{-# INLINE runShiftUnsafe #-}

-----------------------------------------------------------------------------
-- | Runs a 'Shift' effect by explicitly providing a final continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that any
-- continuation may fail locally.
--
-- __Beware__: This interpreter will invalidate all higher-order effects of any
-- interpreter run after it; i.e. 'Polysemy.Reader.local' and
-- 'Polysemy.Writer.censor' will be no-ops, 'Polysemy.Error.catch' will fail
-- to catch exceptions, and 'Polysemy.Writer.listen' will always return 'mempty'.
--
-- __You should therefore use 'runShiftWithCUnsafe' /after/ running all__
-- __interpreters for your higher-order effects.__
runShiftWithCUnsafe :: forall s a r.
                       (a -> Sem r (Maybe s))
                    -> Sem (Shift (Ref (Sem r) (Maybe s)) s ': r) a
                    -> Sem r (Maybe s)
runShiftWithCUnsafe :: (a -> Sem r (Maybe s))
-> Sem (Shift (Ref (Sem r) (Maybe s)) s : r) a -> Sem r (Maybe s)
runShiftWithCUnsafe a -> Sem r (Maybe s)
c (Sem forall (m :: * -> *).
Monad m =>
(forall x.
 Union
   (Shift (Ref (Sem r) (Maybe s)) s : r)
   (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
   x
 -> m x)
-> m a
sem) = (ContT (Maybe s) (Sem r) a
-> (a -> Sem r (Maybe s)) -> Sem r (Maybe s)
forall k (r :: k) (m :: k -> *) a. ContT r m a -> (a -> m r) -> m r
`runContT` a -> Sem r (Maybe s)
c) (ContT (Maybe s) (Sem r) a -> Sem r (Maybe s))
-> ContT (Maybe s) (Sem r) a -> Sem r (Maybe s)
forall a b. (a -> b) -> a -> b
$ (forall x.
 Union
   (Shift (Ref (Sem r) (Maybe s)) s : r)
   (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
   x
 -> ContT (Maybe s) (Sem r) x)
-> ContT (Maybe s) (Sem r) a
forall (m :: * -> *).
Monad m =>
(forall x.
 Union
   (Shift (Ref (Sem r) (Maybe s)) s : r)
   (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
   x
 -> m x)
-> m a
sem ((forall x.
  Union
    (Shift (Ref (Sem r) (Maybe s)) s : r)
    (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
    x
  -> ContT (Maybe s) (Sem r) x)
 -> ContT (Maybe s) (Sem r) a)
-> (forall x.
    Union
      (Shift (Ref (Sem r) (Maybe s)) s : r)
      (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
      x
    -> ContT (Maybe s) (Sem r) x)
-> ContT (Maybe s) (Sem r) a
forall a b. (a -> b) -> a -> b
$ \Union
  (Shift (Ref (Sem r) (Maybe s)) s : r)
  (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
  x
u -> case Union
  (Shift (Ref (Sem r) (Maybe s)) s : r)
  (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
  x
-> Either
     (Union r (Sem (Shift (Ref (Sem r) (Maybe s)) s : r)) x)
     (Weaving
        (Shift (Ref (Sem r) (Maybe s)) s)
        (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
        x)
forall (e :: (* -> *) -> * -> *) (r :: EffectRow) (m :: * -> *) a.
Union (e : r) m a -> Either (Union r m a) (Weaving e m a)
decomp Union
  (Shift (Ref (Sem r) (Maybe s)) s : r)
  (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
  x
u of
  Right Weaving
  (Shift (Ref (Sem r) (Maybe s)) s)
  (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
  x
weaving -> (forall x.
 (x -> Sem r (Maybe s))
 -> Sem (Shift (Ref (Sem r) (Maybe s)) s : r) x -> Sem r (Maybe s))
-> Weaving
     (Shift (Ref (Sem r) (Maybe s)) s)
     (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
     x
-> ContT (Maybe s) (Sem r) x
forall (m :: * -> *) s (r :: EffectRow) a.
Monad m =>
(forall x. (x -> m (Maybe s)) -> Sem r x -> m (Maybe s))
-> Weaving (Shift (Ref m (Maybe s)) s) (Sem r) a
-> ContT (Maybe s) m a
runShiftWeaving forall x.
(x -> Sem r (Maybe s))
-> Sem (Shift (Ref (Sem r) (Maybe s)) s : r) x -> Sem r (Maybe s)
forall s a (r :: EffectRow).
(a -> Sem r (Maybe s))
-> Sem (Shift (Ref (Sem r) (Maybe s)) s : r) a -> Sem r (Maybe s)
runShiftWithCUnsafe Weaving
  (Shift (Ref (Sem r) (Maybe s)) s)
  (Sem (Shift (Ref (Sem r) (Maybe s)) s : r))
  x
weaving
  Left Union r (Sem (Shift (Ref (Sem r) (Maybe s)) s : r)) x
g -> ((x -> Sem r (Maybe s)) -> Sem r (Maybe s))
-> ContT (Maybe s) (Sem r) x
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((x -> Sem r (Maybe s)) -> Sem r (Maybe s))
 -> ContT (Maybe s) (Sem r) x)
-> ((x -> Sem r (Maybe s)) -> Sem r (Maybe s))
-> ContT (Maybe s) (Sem r) x
forall a b. (a -> b) -> a -> b
$ \x -> Sem r (Maybe s)
c' -> Union r (Sem (Shift (Ref (Sem r) (Maybe s)) s : r)) x
-> Sem r (Sem (Shift (Ref (Sem r) (Maybe s)) s : r) x)
forall (r :: EffectRow) (r' :: EffectRow) a.
Union r (Sem r') a -> Sem r (Sem r' a)
embedSem Union r (Sem (Shift (Ref (Sem r) (Maybe s)) s : r)) x
g Sem r (Sem (Shift (Ref (Sem r) (Maybe s)) s : r) x)
-> (Sem (Shift (Ref (Sem r) (Maybe s)) s : r) x -> Sem r (Maybe s))
-> Sem r (Maybe s)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (x -> Sem r (Maybe s))
-> Sem (Shift (Ref (Sem r) (Maybe s)) s : r) x -> Sem r (Maybe s)
forall s a (r :: EffectRow).
(a -> Sem r (Maybe s))
-> Sem (Shift (Ref (Sem r) (Maybe s)) s : r) a -> Sem r (Maybe s)
runShiftWithCUnsafe x -> Sem r (Maybe s)
c'
{-# INLINE runShiftWithCUnsafe #-}

-----------------------------------------------------------------------------
-- | Runs a 'Cont' and a 'Shift' effect simultaneously by providing
-- @'pure' '.' 'Just'@ as the final continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that
-- any continuation may fail locally.
--
-- __Beware__: This interpreter will invalidate all higher-order effects of any
-- interpreter run after it; i.e. 'Polysemy.Reader.local' and
-- 'Polysemy.Writer.censor' will be no-ops, 'Polysemy.Error.catch' will fail
-- to catch exceptions, and 'Polysemy.Writer.listen' will always return 'mempty'.
--
-- __You should therefore use 'runContShiftUnsafe' /after/ running all__
-- __interpreters for your higher-order effects.__
runContShiftUnsafe :: Sem (   Cont (Ref (Sem r) (Maybe a))
                           ': Shift (Ref (Sem r) (Maybe a)) a
                           ': r) a
                   -> Sem r (Maybe a)
runContShiftUnsafe :: Sem
  (Cont (Ref (Sem r) (Maybe a))
     : Shift (Ref (Sem r) (Maybe a)) a : r)
  a
-> Sem r (Maybe a)
runContShiftUnsafe = (a -> Sem r (Maybe a))
-> Sem
     (Cont (Ref (Sem r) (Maybe a))
        : Shift (Ref (Sem r) (Maybe a)) a : r)
     a
-> Sem r (Maybe a)
forall s a (r :: EffectRow).
(a -> Sem r (Maybe s))
-> Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r)
     a
-> Sem r (Maybe s)
runContShiftWithCUnsafe (Maybe a -> Sem r (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe a -> Sem r (Maybe a))
-> (a -> Maybe a) -> a -> Sem r (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe a
forall a. a -> Maybe a
Just)
{-# INLINE runContShiftUnsafe #-}

-----------------------------------------------------------------------------
-- | Runs a 'Cont' and a 'Shift' effect simultaneously by explicitly providing
-- a final continuation.
--
-- The final return type is wrapped in a 'Maybe' due to the fact that
-- any continuation may fail locally.
--
-- __Beware__: This interpreter will invalidate all higher-order effects of any
-- interpreter run after it; i.e. 'Polysemy.Reader.local' and
-- 'Polysemy.Writer.censor' will be no-ops, 'Polysemy.Error.catch' will fail
-- to catch exceptions, and 'Polysemy.Writer.listen' will always return 'mempty'.
--
-- __You should therefore use 'runContShiftWithCUnsafe' /after/ running all__
-- __interpreters for your higher-order effects.__
runContShiftWithCUnsafe :: forall s a r.
                           (a -> Sem r (Maybe s))
                        -> Sem (   Cont (Ref (Sem r) (Maybe s))
                                ': Shift (Ref (Sem r) (Maybe s)) s
                                ': r) a
                        -> Sem r (Maybe s)
runContShiftWithCUnsafe :: (a -> Sem r (Maybe s))
-> Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r)
     a
-> Sem r (Maybe s)
runContShiftWithCUnsafe a -> Sem r (Maybe s)
c (Sem forall (m :: * -> *).
Monad m =>
(forall x.
 Union
   (Cont (Ref (Sem r) (Maybe s))
      : Shift (Ref (Sem r) (Maybe s)) s : r)
   (Sem
      (Cont (Ref (Sem r) (Maybe s))
         : Shift (Ref (Sem r) (Maybe s)) s : r))
   x
 -> m x)
-> m a
m) = (ContT (Maybe s) (Sem r) a
-> (a -> Sem r (Maybe s)) -> Sem r (Maybe s)
forall k (r :: k) (m :: k -> *) a. ContT r m a -> (a -> m r) -> m r
`runContT` a -> Sem r (Maybe s)
c) (ContT (Maybe s) (Sem r) a -> Sem r (Maybe s))
-> ContT (Maybe s) (Sem r) a -> Sem r (Maybe s)
forall a b. (a -> b) -> a -> b
$ (forall x.
 Union
   (Cont (Ref (Sem r) (Maybe s))
      : Shift (Ref (Sem r) (Maybe s)) s : r)
   (Sem
      (Cont (Ref (Sem r) (Maybe s))
         : Shift (Ref (Sem r) (Maybe s)) s : r))
   x
 -> ContT (Maybe s) (Sem r) x)
-> ContT (Maybe s) (Sem r) a
forall (m :: * -> *).
Monad m =>
(forall x.
 Union
   (Cont (Ref (Sem r) (Maybe s))
      : Shift (Ref (Sem r) (Maybe s)) s : r)
   (Sem
      (Cont (Ref (Sem r) (Maybe s))
         : Shift (Ref (Sem r) (Maybe s)) s : r))
   x
 -> m x)
-> m a
m ((forall x.
  Union
    (Cont (Ref (Sem r) (Maybe s))
       : Shift (Ref (Sem r) (Maybe s)) s : r)
    (Sem
       (Cont (Ref (Sem r) (Maybe s))
          : Shift (Ref (Sem r) (Maybe s)) s : r))
    x
  -> ContT (Maybe s) (Sem r) x)
 -> ContT (Maybe s) (Sem r) a)
-> (forall x.
    Union
      (Cont (Ref (Sem r) (Maybe s))
         : Shift (Ref (Sem r) (Maybe s)) s : r)
      (Sem
         (Cont (Ref (Sem r) (Maybe s))
            : Shift (Ref (Sem r) (Maybe s)) s : r))
      x
    -> ContT (Maybe s) (Sem r) x)
-> ContT (Maybe s) (Sem r) a
forall a b. (a -> b) -> a -> b
$ \Union
  (Cont (Ref (Sem r) (Maybe s))
     : Shift (Ref (Sem r) (Maybe s)) s : r)
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
u -> case Union
  (Cont (Ref (Sem r) (Maybe s))
     : Shift (Ref (Sem r) (Maybe s)) s : r)
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
-> Either
     (Union
        (Shift (Ref (Sem r) (Maybe s)) s : r)
        (Sem
           (Cont (Ref (Sem r) (Maybe s))
              : Shift (Ref (Sem r) (Maybe s)) s : r))
        x)
     (Weaving
        (Cont (Ref (Sem r) (Maybe s)))
        (Sem
           (Cont (Ref (Sem r) (Maybe s))
              : Shift (Ref (Sem r) (Maybe s)) s : r))
        x)
forall (e :: (* -> *) -> * -> *) (r :: EffectRow) (m :: * -> *) a.
Union (e : r) m a -> Either (Union r m a) (Weaving e m a)
decomp Union
  (Cont (Ref (Sem r) (Maybe s))
     : Shift (Ref (Sem r) (Maybe s)) s : r)
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
u of
  Right Weaving
  (Cont (Ref (Sem r) (Maybe s)))
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
weaving -> (forall x.
 (x -> Sem r (Maybe s))
 -> Sem
      (Cont (Ref (Sem r) (Maybe s))
         : Shift (Ref (Sem r) (Maybe s)) s : r)
      x
 -> Sem r (Maybe s))
-> Weaving
     (Cont (Ref (Sem r) (Maybe s)))
     (Sem
        (Cont (Ref (Sem r) (Maybe s))
           : Shift (Ref (Sem r) (Maybe s)) s : r))
     x
-> ContT (Maybe s) (Sem r) x
forall (m :: * -> *) s (r :: EffectRow) a.
Monad m =>
(forall x. (x -> m s) -> Sem r x -> m s)
-> Weaving (Cont (Ref m s)) (Sem r) a -> ContT s m a
runContWeaving forall x.
(x -> Sem r (Maybe s))
-> Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r)
     x
-> Sem r (Maybe s)
forall s a (r :: EffectRow).
(a -> Sem r (Maybe s))
-> Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r)
     a
-> Sem r (Maybe s)
runContShiftWithCUnsafe Weaving
  (Cont (Ref (Sem r) (Maybe s)))
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
weaving
  Left Union
  (Shift (Ref (Sem r) (Maybe s)) s : r)
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
g -> case Union
  (Shift (Ref (Sem r) (Maybe s)) s : r)
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
-> Either
     (Union
        r
        (Sem
           (Cont (Ref (Sem r) (Maybe s))
              : Shift (Ref (Sem r) (Maybe s)) s : r))
        x)
     (Weaving
        (Shift (Ref (Sem r) (Maybe s)) s)
        (Sem
           (Cont (Ref (Sem r) (Maybe s))
              : Shift (Ref (Sem r) (Maybe s)) s : r))
        x)
forall (e :: (* -> *) -> * -> *) (r :: EffectRow) (m :: * -> *) a.
Union (e : r) m a -> Either (Union r m a) (Weaving e m a)
decomp Union
  (Shift (Ref (Sem r) (Maybe s)) s : r)
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
g of
    Right Weaving
  (Shift (Ref (Sem r) (Maybe s)) s)
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
weaving -> (forall x.
 (x -> Sem r (Maybe s))
 -> Sem
      (Cont (Ref (Sem r) (Maybe s))
         : Shift (Ref (Sem r) (Maybe s)) s : r)
      x
 -> Sem r (Maybe s))
-> Weaving
     (Shift (Ref (Sem r) (Maybe s)) s)
     (Sem
        (Cont (Ref (Sem r) (Maybe s))
           : Shift (Ref (Sem r) (Maybe s)) s : r))
     x
-> ContT (Maybe s) (Sem r) x
forall (m :: * -> *) s (r :: EffectRow) a.
Monad m =>
(forall x. (x -> m (Maybe s)) -> Sem r x -> m (Maybe s))
-> Weaving (Shift (Ref m (Maybe s)) s) (Sem r) a
-> ContT (Maybe s) m a
runShiftWeaving forall x.
(x -> Sem r (Maybe s))
-> Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r)
     x
-> Sem r (Maybe s)
forall s a (r :: EffectRow).
(a -> Sem r (Maybe s))
-> Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r)
     a
-> Sem r (Maybe s)
runContShiftWithCUnsafe Weaving
  (Shift (Ref (Sem r) (Maybe s)) s)
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
weaving
    Left Union
  r
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
g'       -> ((x -> Sem r (Maybe s)) -> Sem r (Maybe s))
-> ContT (Maybe s) (Sem r) x
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((x -> Sem r (Maybe s)) -> Sem r (Maybe s))
 -> ContT (Maybe s) (Sem r) x)
-> ((x -> Sem r (Maybe s)) -> Sem r (Maybe s))
-> ContT (Maybe s) (Sem r) x
forall a b. (a -> b) -> a -> b
$ \x -> Sem r (Maybe s)
c' -> Union
  r
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
-> Sem
     r
     (Sem
        (Cont (Ref (Sem r) (Maybe s))
           : Shift (Ref (Sem r) (Maybe s)) s : r)
        x)
forall (r :: EffectRow) (r' :: EffectRow) a.
Union r (Sem r') a -> Sem r (Sem r' a)
embedSem Union
  r
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r))
  x
g' Sem
  r
  (Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r)
     x)
-> (Sem
      (Cont (Ref (Sem r) (Maybe s))
         : Shift (Ref (Sem r) (Maybe s)) s : r)
      x
    -> Sem r (Maybe s))
-> Sem r (Maybe s)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (x -> Sem r (Maybe s))
-> Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r)
     x
-> Sem r (Maybe s)
forall s a (r :: EffectRow).
(a -> Sem r (Maybe s))
-> Sem
     (Cont (Ref (Sem r) (Maybe s))
        : Shift (Ref (Sem r) (Maybe s)) s : r)
     a
-> Sem r (Maybe s)
runContShiftWithCUnsafe x -> Sem r (Maybe s)
c'
{-# INLINE runContShiftWithCUnsafe #-}