{-# LANGUAGE AllowAmbiguousTypes, Trustworthy #-}
module Polysemy.Shift
(
module Polysemy.Cont
, Shift(..)
, trap
, invoke
, abort
, reset
, reset'
, shift
, runShiftPure
, runShiftM
, shiftToFinal
, runShiftWithCPure
, runShiftWithCM
, runContShiftPure
, runContShiftM
, runContShiftWithCPure
, runContShiftWithCM
, 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
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}