1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00

Define a reinterpretEffect handler.

This commit is contained in:
Rob Rix 2018-05-08 16:28:28 -04:00
parent 4799bffeb0
commit a1b1f78c95

View File

@ -13,6 +13,7 @@ module Control.Effect
, run
, runM
, runEffect
, reinterpretEffect
, raiseHandler
, runReader
, runState
@ -70,6 +71,9 @@ runM = Eff.runM . lower
runEffect :: Effectful m => (forall v . effect v -> (v -> m effects a) -> m effects a) -> m (effect ': effects) a -> m effects a
runEffect handler = raiseHandler (Eff.relay pure (\ effect yield -> lower (handler effect (raise . yield))))
reinterpretEffect :: Effectful m => (forall x . effect x -> m (newEffect ': effects) x) -> m (effect ': effects) a -> m (newEffect ': effects) a
reinterpretEffect handler = raiseHandler (Eff.reinterpret (lower . handler))
-- | Raise a handler on 'Eff.Eff' to a handler on some 'Effectful' @m@.
raiseHandler :: Effectful m => (Eff.Eff effectsA a -> Eff.Eff effectsB b) -> m effectsA a -> m effectsB b
raiseHandler handler = raise . handler . lower