{-# LANGUAGE DerivingVia #-}
module Control.Effect.Regional
(
Regional(..)
, Hoist
, regionally
, hoist
, runHoist
, hoistToFinal
, threadRegionalViaOptional
, powerAlgHoist
, powerAlgHoistFinal
, HoistC
, HoistToFinalC
) where
import Control.Effect
import Control.Effect.Carrier
import Control.Effect.Type.Regional
import Control.Effect.Type.Optional
import Control.Effect.Internal.Regional
import Control.Monad.Trans.Control (control)
regionally :: Eff (Regional s) m => s -> m a -> m a
regionally :: s -> m a -> m a
regionally s
s m a
m = Regional s m a -> m a
forall (e :: Effect) (m :: * -> *) a.
(Member e (Derivs m), Carrier m) =>
e m a -> m a
send (s -> m a -> Regional s m a
forall s (m :: * -> *) a. s -> m a -> Regional s m a
Regionally s
s m a
m)
{-# INLINE regionally #-}
hoist :: Eff (Hoist b) m => (forall x. b x -> b x) -> m a -> m a
hoist :: (forall x. b x -> b x) -> m a -> m a
hoist forall x. b x -> b x
n = HoistCall b -> m a -> m a
forall s (m :: * -> *) a. Eff (Regional s) m => s -> m a -> m a
regionally ((forall x. b x -> b x) -> HoistCall b
forall k (b :: k -> *).
(forall (x :: k). b x -> b x) -> HoistCall b
HoistCall forall x. b x -> b x
n)
{-# INLINE hoist #-}
type HoistToFinalC b = InterpretPrimC HoistToFinalH (Hoist b)
runHoist :: Carrier m
=> HoistC m a
-> m a
runHoist :: HoistC m a -> m a
runHoist = HoistC m a -> m a
forall k (m :: k -> *) (a :: k). HoistC m a -> m a
unHoistC
{-# INLINE runHoist #-}
hoistToFinal :: ( MonadBaseControl b m
, Carrier m
)
=> HoistToFinalC b m a
-> m a
hoistToFinal :: HoistToFinalC b m a -> m a
hoistToFinal = HoistToFinalC b m a -> m a
forall h (e :: Effect) (m :: * -> *) a.
PrimHandler h e m =>
InterpretPrimC h e m a -> m a
interpretPrimViaHandler
{-# INLINE hoistToFinal #-}
powerAlgHoist :: forall m p a
. Algebra' p m a
-> Algebra' (Hoist m ': p) m a
powerAlgHoist :: Algebra' p m a -> Algebra' (Hoist m : p) m a
powerAlgHoist Algebra' p m a
alg = Algebra' p m a
-> (Regional (HoistCall m) m a -> m a)
-> Algebra' (Hoist m : p) 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' p m a
alg ((Regional (HoistCall m) m a -> m a) -> Algebra' (Hoist m : p) m a)
-> (Regional (HoistCall m) m a -> m a)
-> Algebra' (Hoist m : p) m a
forall a b. (a -> b) -> a -> b
$ \(Regionally (HoistCall forall x. m x -> m x
n) m a
m) -> m a -> m a
forall x. m x -> m x
n m a
m
{-# INLINE powerAlgHoist #-}
powerAlgHoistFinal :: forall b m p a
. MonadBaseControl b m
=> Algebra' p m a
-> Algebra' (Hoist b ': p) m a
powerAlgHoistFinal :: Algebra' p m a -> Algebra' (Hoist b : p) m a
powerAlgHoistFinal Algebra' p m a
alg = Algebra' p m a
-> (Regional (HoistCall b) m a -> m a)
-> Algebra' (Hoist b : p) 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' p m a
alg ((Regional (HoistCall b) m a -> m a) -> Algebra' (Hoist b : p) m a)
-> (Regional (HoistCall b) m a -> m a)
-> Algebra' (Hoist b : p) m a
forall a b. (a -> b) -> a -> b
$ \case
Regionally (HoistCall forall x. b x -> b x
n) m a
m -> (RunInBase m b -> b (StM m a)) -> m a
forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b (StM m a)) -> m a
control ((RunInBase m b -> b (StM m a)) -> m a)
-> (RunInBase m b -> b (StM m a)) -> m a
forall a b. (a -> b) -> a -> b
$ \RunInBase m b
lower -> b (StM m a) -> b (StM m a)
forall x. b x -> b x
n (m a -> b (StM m a)
RunInBase m b
lower m a
m)
{-# INLINE powerAlgHoistFinal #-}