{-# LANGUAGE TypeOperators, -- h :* e (looks nice but not required)
ConstraintKinds, -- type (h ?: e) = In h e (looks nice but not required)
FlexibleInstances, -- instance Sub () e (non type variable in head)
FlexibleContexts, -- (State Int ?: e) => ... (non type variable argument)
DataKinds, TypeFamilies, -- type family HEqual h h' :: Bool
UndecidableInstances, -- InEq (HEqual h h') h h' e => ... (duplicate instance variable)
GADTs,
MultiParamTypeClasses,
FunctionalDependencies,
Rank2Types
#-}
module Control.Ev.Eff(
Eff
, runEff
, (:?)
, (:*)
, perform
, handler
, handlerRet
, handlerHide
, mask
, Op
, value
, function
, except
, operation
, Local
, local
, localRet
, handlerLocal
, handlerLocalRet
, lget
, lput
, lmodify
, localGet
, localPut
, localModify
) where
import Prelude hiding (read,flip)
import Control.Monad( ap, liftM )
import Data.Type.Equality( (:~:)( Refl ) )
import Control.Ev.Ctl hiding (Local)
import Data.IORef
infixr 5 :*
data (h :: * -> * -> *) :* e
data Context e where
CCons :: !(Marker ans) -> !(h e' ans) -> !(ContextT e e') -> !(Context e) -> Context (h :* e)
CNil :: Context ()
data ContextT e e' where
CTCons :: !(Marker ans) -> !(h e' ans) -> !(ContextT e e') -> ContextT e (h :* e)
CTId :: ContextT e e
applyT :: ContextT e e' -> Context e -> Context e'
applyT :: ContextT e e' -> Context e -> Context e'
applyT (CTCons Marker ans
m h e' ans
h ContextT e e'
g) Context e
ctx = Marker ans
-> h e' ans -> ContextT e e' -> Context e -> Context (h :* e)
forall ans (h :: * -> * -> *) e' e.
Marker ans
-> h e' ans -> ContextT e e' -> Context e -> Context (h :* e)
CCons Marker ans
m h e' ans
h ContextT e e'
g Context e
ctx
applyT (ContextT e e'
CTId) Context e
ctx = Context e
Context e'
ctx
ctail :: Context (h :* e) -> Context e
ctail :: Context (h :* e) -> Context e
ctail (CCons Marker ans
_ h e' ans
_ ContextT e e'
_ Context e
ctx) = Context e
Context e
ctx
newtype Eff e a = Eff (Context e -> Ctl a)
lift :: Ctl a -> Eff e a
lift :: Ctl a -> Eff e a
lift Ctl a
ctl = (Context e -> Ctl a) -> Eff e a
forall e a. (Context e -> Ctl a) -> Eff e a
Eff (\Context e
_ -> Ctl a
ctl)
under :: Context e -> Eff e a -> Ctl a
under :: Context e -> Eff e a -> Ctl a
under Context e
ctx (Eff Context e -> Ctl a
eff) = Context e -> Ctl a
eff Context e
ctx
instance Functor (Eff e) where
fmap :: (a -> b) -> Eff e a -> Eff e b
fmap = (a -> b) -> Eff e a -> Eff e b
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM
instance Applicative (Eff e) where
pure :: a -> Eff e a
pure = a -> Eff e a
forall (m :: * -> *) a. Monad m => a -> m a
return
<*> :: Eff e (a -> b) -> Eff e a -> Eff e b
(<*>) = Eff e (a -> b) -> Eff e a -> Eff e b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap
instance Monad (Eff e) where
return :: a -> Eff e a
return a
x = (Context e -> Ctl a) -> Eff e a
forall e a. (Context e -> Ctl a) -> Eff e a
Eff (\Context e
ctx -> a -> Ctl a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x)
(Eff Context e -> Ctl a
eff) >>= :: Eff e a -> (a -> Eff e b) -> Eff e b
>>= a -> Eff e b
f = (Context e -> Ctl b) -> Eff e b
forall e a. (Context e -> Ctl a) -> Eff e a
Eff (\Context e
ctx -> do a
x <- Context e -> Ctl a
eff Context e
ctx
Context e -> Eff e b -> Ctl b
forall e a. Context e -> Eff e a -> Ctl a
under Context e
ctx (a -> Eff e b
f a
x))
{-# INLINE handler #-}
handler :: h e ans -> Eff (h :* e) ans -> Eff e ans
handler :: h e ans -> Eff (h :* e) ans -> Eff e ans
handler h e ans
h Eff (h :* e) ans
action
= (Context e -> Ctl ans) -> Eff e ans
forall e a. (Context e -> Ctl a) -> Eff e a
Eff (\Context e
ctx -> (Marker ans -> Ctl ans) -> Ctl ans
forall a. (Marker a -> Ctl a) -> Ctl a
prompt ((Marker ans -> Ctl ans) -> Ctl ans)
-> (Marker ans -> Ctl ans) -> Ctl ans
forall a b. (a -> b) -> a -> b
$ \Marker ans
m ->
do Context (h :* e) -> Eff (h :* e) ans -> Ctl ans
forall e a. Context e -> Eff e a -> Ctl a
under (Marker ans
-> h e ans -> ContextT e e -> Context e -> Context (h :* e)
forall ans (h :: * -> * -> *) e' e.
Marker ans
-> h e' ans -> ContextT e e' -> Context e -> Context (h :* e)
CCons Marker ans
m h e ans
h ContextT e e
forall e. ContextT e e
CTId Context e
ctx) Eff (h :* e) ans
action)
runEff :: Eff () a -> a
runEff :: Eff () a -> a
runEff (Eff Context () -> Ctl a
eff) = Ctl a -> a
forall a. Ctl a -> a
runCtl (Context () -> Ctl a
eff Context ()
CNil)
{-# INLINE handlerRet #-}
handlerRet :: (ans -> a) -> h e a -> Eff (h :* e) ans -> Eff e a
handlerRet :: (ans -> a) -> h e a -> Eff (h :* e) ans -> Eff e a
handlerRet ans -> a
ret h e a
h Eff (h :* e) ans
action
= h e a -> Eff (h :* e) a -> Eff e a
forall (h :: * -> * -> *) e ans.
h e ans -> Eff (h :* e) ans -> Eff e ans
handler h e a
h (do ans
x <- Eff (h :* e) ans
action; a -> Eff (h :* e) a
forall (m :: * -> *) a. Monad m => a -> m a
return (ans -> a
ret ans
x))
{-# INLINE handlerHide #-}
handlerHide :: h (h' :* e) ans -> Eff (h :* e) ans -> Eff (h' :* e) ans
handlerHide :: h (h' :* e) ans -> Eff (h :* e) ans -> Eff (h' :* e) ans
handlerHide h (h' :* e) ans
h Eff (h :* e) ans
action
= (Context (h' :* e) -> Ctl ans) -> Eff (h' :* e) ans
forall e a. (Context e -> Ctl a) -> Eff e a
Eff (\(CCons Marker ans
m' h e' ans
h' ContextT e e'
g' Context e
ctx') -> (Marker ans -> Ctl ans) -> Ctl ans
forall a. (Marker a -> Ctl a) -> Ctl a
prompt (\Marker ans
m -> Context (h :* e) -> Eff (h :* e) ans -> Ctl ans
forall e a. Context e -> Eff e a -> Ctl a
under (Marker ans
-> h (h' :* e) ans
-> ContextT e (h' :* e)
-> Context e
-> Context (h :* e)
forall ans (h :: * -> * -> *) e' e.
Marker ans
-> h e' ans -> ContextT e e' -> Context e -> Context (h :* e)
CCons Marker ans
m h (h' :* e) ans
h (Marker ans -> h e' ans -> ContextT e e' -> ContextT e (h :* e)
forall ans (h :: * -> * -> *) e' e.
Marker ans -> h e' ans -> ContextT e e' -> ContextT e (h :* e)
CTCons Marker ans
m' h e' ans
h' ContextT e e'
g') Context e
ctx') Eff (h :* e) ans
Eff (h :* e) ans
action))
{-# INLINE handlerHideRetEff #-}
handlerHideRetEff :: (ans -> Eff (h' :* e) b) -> h (h' :* e) b -> Eff (h :* e) ans -> Eff (h' :* e) b
handlerHideRetEff :: (ans -> Eff (h' :* e) b)
-> h (h' :* e) b -> Eff (h :* e) ans -> Eff (h' :* e) b
handlerHideRetEff ans -> Eff (h' :* e) b
ret h (h' :* e) b
h Eff (h :* e) ans
action
= (Context (h' :* e) -> Ctl b) -> Eff (h' :* e) b
forall e a. (Context e -> Ctl a) -> Eff e a
Eff (\ctx :: Context (h' :* e)
ctx@(CCons Marker ans
m' h e' ans
h' ContextT e e'
g' Context e
ctx') -> do (Marker b -> Ctl b) -> Ctl b
forall a. (Marker a -> Ctl a) -> Ctl a
prompt (\Marker b
m -> do ans
x <- Context (h :* e) -> Eff (h :* e) ans -> Ctl ans
forall e a. Context e -> Eff e a -> Ctl a
under (Marker b
-> h (h' :* e) b
-> ContextT e (h' :* e)
-> Context e
-> Context (h :* e)
forall ans (h :: * -> * -> *) e' e.
Marker ans
-> h e' ans -> ContextT e e' -> Context e -> Context (h :* e)
CCons Marker b
m h (h' :* e) b
h (Marker ans -> h e' ans -> ContextT e e' -> ContextT e (h :* e)
forall ans (h :: * -> * -> *) e' e.
Marker ans -> h e' ans -> ContextT e e' -> ContextT e (h :* e)
CTCons Marker ans
m' h e' ans
h' ContextT e e'
g') Context e
ctx') Eff (h :* e) ans
Eff (h :* e) ans
action
Context (h' :* e) -> Eff (h' :* e) b -> Ctl b
forall e a. Context e -> Eff e a -> Ctl a
under Context (h' :* e)
ctx (ans -> Eff (h' :* e) b
ret ans
x)))
mask :: Eff e ans -> Eff (h :* e) ans
mask :: Eff e ans -> Eff (h :* e) ans
mask (Eff Context e -> Ctl ans
f) = (Context (h :* e) -> Ctl ans) -> Eff (h :* e) ans
forall e a. (Context e -> Ctl a) -> Eff e a
Eff (\Context (h :* e)
ctx -> Context e -> Ctl ans
f (Context (h :* e) -> Context e
forall (h :: * -> * -> *) e. Context (h :* e) -> Context e
ctail Context (h :* e)
ctx))
type h :? e = In h e
data SubContext h = forall e. SubContext !(Context (h :* e))
class In h e where
subContext :: Context e -> SubContext h
instance (InEq (HEqual h h') h h' w) => In h (h' :* w) where
subContext :: Context (h' :* w) -> SubContext h
subContext = Context (h' :* w) -> SubContext h
forall (iseq :: Bool) (h :: * -> * -> *) (h' :: * -> * -> *) e.
InEq iseq h h' e =>
Context (h' :* e) -> SubContext h
subContextEq
type family HEqual (h :: * -> * -> *) (h' :: * -> * -> *) :: Bool where
HEqual h h = 'True
HEqual h h' = 'False
class (iseq ~ HEqual h h') => InEq iseq h h' e where
subContextEq :: Context (h' :* e) -> SubContext h
instance (h ~ h') => InEq 'True h h' e where
subContextEq :: Context (h' :* e) -> SubContext h
subContextEq Context (h' :* e)
ctx = Context (h' :* e) -> SubContext h'
forall (h :: * -> * -> *) e. Context (h :* e) -> SubContext h
SubContext Context (h' :* e)
ctx
instance ('False ~ HEqual h h', In h e) => InEq 'False h h' e where
subContextEq :: Context (h' :* e) -> SubContext h
subContextEq Context (h' :* e)
ctx = Context e -> SubContext h
forall (h :: * -> * -> *) e. In h e => Context e -> SubContext h
subContext (Context (h' :* e) -> Context e
forall (h :: * -> * -> *) e. Context (h :* e) -> Context e
ctail Context (h' :* e)
ctx)
{-# INLINE withSubContext #-}
withSubContext :: (In h e) => (SubContext h -> Ctl a) -> Eff e a
withSubContext :: (SubContext h -> Ctl a) -> Eff e a
withSubContext SubContext h -> Ctl a
f
= (Context e -> Ctl a) -> Eff e a
forall e a. (Context e -> Ctl a) -> Eff e a
Eff (\Context e
ctx -> SubContext h -> Ctl a
f (Context e -> SubContext h
forall (h :: * -> * -> *) e. In h e => Context e -> SubContext h
subContext Context e
ctx))
data Op a b e ans = Op { Op a b e ans -> Marker ans -> Context e -> a -> Ctl b
applyOp :: !(Marker ans -> Context e -> a -> Ctl b) }
{-# INLINE perform #-}
perform :: (h :? e) => (forall e' ans. h e' ans -> Op a b e' ans) -> a -> Eff e b
perform :: (forall e' ans. h e' ans -> Op a b e' ans) -> a -> Eff e b
perform forall e' ans. h e' ans -> Op a b e' ans
selectOp a
x
= (SubContext h -> Ctl b) -> Eff e b
forall (h :: * -> * -> *) e a.
In h e =>
(SubContext h -> Ctl a) -> Eff e a
withSubContext (\(SubContext (CCons Marker ans
m h e' ans
h ContextT e e'
g Context e
ctx)) -> Op a b e' ans -> Marker ans -> Context e' -> a -> Ctl b
forall a b e ans.
Op a b e ans -> Marker ans -> Context e -> a -> Ctl b
applyOp (h e' ans -> Op a b e' ans
forall e' ans. h e' ans -> Op a b e' ans
selectOp h e' ans
h e' ans
h) Marker ans
m (ContextT e e' -> Context e -> Context e'
forall e e'. ContextT e e' -> Context e -> Context e'
applyT ContextT e e'
g Context e
ctx) a
x)
value :: a -> Op () a e ans
value :: a -> Op () a e ans
value a
x = (() -> Eff e a) -> Op () a e ans
forall a e b ans. (a -> Eff e b) -> Op a b e ans
function (\() -> a -> Eff e a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x)
function :: (a -> Eff e b) -> Op a b e ans
function :: (a -> Eff e b) -> Op a b e ans
function a -> Eff e b
f = (Marker ans -> Context e -> a -> Ctl b) -> Op a b e ans
forall a b e ans.
(Marker ans -> Context e -> a -> Ctl b) -> Op a b e ans
Op (\Marker ans
_ Context e
ctx a
x -> Context e -> Eff e b -> Ctl b
forall e a. Context e -> Eff e a -> Ctl a
under Context e
ctx (a -> Eff e b
f a
x))
operation :: (a -> (b -> Eff e ans) -> Eff e ans) -> Op a b e ans
operation :: (a -> (b -> Eff e ans) -> Eff e ans) -> Op a b e ans
operation a -> (b -> Eff e ans) -> Eff e ans
f = (Marker ans -> Context e -> a -> Ctl b) -> Op a b e ans
forall a b e ans.
(Marker ans -> Context e -> a -> Ctl b) -> Op a b e ans
Op (\Marker ans
m Context e
ctx a
x -> Marker ans -> ((b -> Ctl ans) -> Ctl ans) -> Ctl b
forall ans b. Marker ans -> ((b -> Ctl ans) -> Ctl ans) -> Ctl b
yield Marker ans
m (((b -> Ctl ans) -> Ctl ans) -> Ctl b)
-> ((b -> Ctl ans) -> Ctl ans) -> Ctl b
forall a b. (a -> b) -> a -> b
$ \b -> Ctl ans
ctlk ->
let k :: b -> Eff e ans
k b
y = (Context e -> Ctl ans) -> Eff e ans
forall e a. (Context e -> Ctl a) -> Eff e a
Eff (\Context e
ctx' -> Context e -> Context e -> (b -> Ctl ans) -> b -> Ctl ans
forall e b a. Context e -> Context e -> (b -> Ctl a) -> b -> Ctl a
guard Context e
ctx Context e
ctx' b -> Ctl ans
ctlk b
y)
in Context e -> Eff e ans -> Ctl ans
forall e a. Context e -> Eff e a -> Ctl a
under Context e
ctx (a -> (b -> Eff e ans) -> Eff e ans
f a
x b -> Eff e ans
k))
except :: (a -> Eff e ans) -> Op a b e ans
except :: (a -> Eff e ans) -> Op a b e ans
except a -> Eff e ans
f = (Marker ans -> Context e -> a -> Ctl b) -> Op a b e ans
forall a b e ans.
(Marker ans -> Context e -> a -> Ctl b) -> Op a b e ans
Op (\Marker ans
m Context e
ctx a
x -> Marker ans -> ((b -> Ctl ans) -> Ctl ans) -> Ctl b
forall ans b. Marker ans -> ((b -> Ctl ans) -> Ctl ans) -> Ctl b
yield Marker ans
m (((b -> Ctl ans) -> Ctl ans) -> Ctl b)
-> ((b -> Ctl ans) -> Ctl ans) -> Ctl b
forall a b. (a -> b) -> a -> b
$ \b -> Ctl ans
ctlk -> Context e -> Eff e ans -> Ctl ans
forall e a. Context e -> Eff e a -> Ctl a
under Context e
ctx (a -> Eff e ans
f a
x))
guard :: Context e -> Context e -> (b -> Ctl a) -> b -> Ctl a
guard :: Context e -> Context e -> (b -> Ctl a) -> b -> Ctl a
guard Context e
ctx1 Context e
ctx2 b -> Ctl a
k b
x = if (Context e
ctx1 Context e -> Context e -> Bool
forall a. Eq a => a -> a -> Bool
== Context e
ctx2) then b -> Ctl a
k b
x else [Char] -> Ctl a
forall a. HasCallStack => [Char] -> a
error [Char]
"Control.Ev.Eff.guard: unscoped resumption under a different handler context"
instance Eq (Context e) where
(CCons Marker ans
m1 h e' ans
_ ContextT e e'
_ Context e
ctx1) == :: Context e -> Context e -> Bool
== (CCons Marker ans
m2 h e' ans
_ ContextT e e'
_ Context e
ctx2) = (Marker ans -> Marker ans -> Bool
forall a b. Marker a -> Marker b -> Bool
markerEq Marker ans
m1 Marker ans
m2) Bool -> Bool -> Bool
&& (Context e
ctx1 Context e -> Context e -> Bool
forall a. Eq a => a -> a -> Bool
== Context e
Context e
ctx2)
Context e
CNil == Context e
CNil = Bool
True
newtype Local a e ans = Local (IORef a)
{-# INLINE lget #-}
lget :: Local a e ans -> Op () a e ans
lget :: Local a e ans -> Op () a e ans
lget (Local IORef a
r) = (Marker ans -> Context e -> () -> Ctl a) -> Op () a e ans
forall a b e ans.
(Marker ans -> Context e -> a -> Ctl b) -> Op a b e ans
Op (\Marker ans
m Context e
ctx ()
x -> IO a -> Ctl a
forall a. IO a -> Ctl a
unsafeIO (() -> IO a -> IO a
seq ()
x (IO a -> IO a) -> IO a -> IO a
forall a b. (a -> b) -> a -> b
$ IORef a -> IO a
forall a. IORef a -> IO a
readIORef IORef a
r))
{-# INLINE lput #-}
lput :: Local a e ans -> Op a () e ans
lput :: Local a e ans -> Op a () e ans
lput (Local IORef a
r) = (Marker ans -> Context e -> a -> Ctl ()) -> Op a () e ans
forall a b e ans.
(Marker ans -> Context e -> a -> Ctl b) -> Op a b e ans
Op (\Marker ans
m Context e
ctx a
x -> IO () -> Ctl ()
forall a. IO a -> Ctl a
unsafeIO (IORef a -> a -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef a
r a
x))
{-# INLINE lmodify #-}
lmodify :: Local a e ans -> Op (a -> a) () e ans
lmodify :: Local a e ans -> Op (a -> a) () e ans
lmodify (Local IORef a
r) = (Marker ans -> Context e -> (a -> a) -> Ctl ())
-> Op (a -> a) () e ans
forall a b e ans.
(Marker ans -> Context e -> a -> Ctl b) -> Op a b e ans
Op (\Marker ans
m Context e
ctx a -> a
f -> IO () -> Ctl ()
forall a. IO a -> Ctl a
unsafeIO (do{ a
x <- IORef a -> IO a
forall a. IORef a -> IO a
readIORef IORef a
r; IORef a -> a -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef a
r (a -> IO ()) -> a -> IO ()
forall a b. (a -> b) -> a -> b
$! (a -> a
f a
x) }))
localGet :: Eff (Local a :* e) a
localGet :: Eff (Local a :* e) a
localGet = (forall e' ans. Local a e' ans -> Op () a e' ans)
-> () -> Eff (Local a :* e) a
forall (h :: * -> * -> *) e a b.
(h :? e) =>
(forall e' ans. h e' ans -> Op a b e' ans) -> a -> Eff e b
perform forall e' ans. Local a e' ans -> Op () a e' ans
forall a e ans. Local a e ans -> Op () a e ans
lget ()
localPut :: a -> Eff (Local a :* e) ()
localPut :: a -> Eff (Local a :* e) ()
localPut a
x = (forall e' ans. Local a e' ans -> Op a () e' ans)
-> a -> Eff (Local a :* e) ()
forall (h :: * -> * -> *) e a b.
(h :? e) =>
(forall e' ans. h e' ans -> Op a b e' ans) -> a -> Eff e b
perform forall e' ans. Local a e' ans -> Op a () e' ans
forall a e ans. Local a e ans -> Op a () e ans
lput a
x
localModify :: (a -> a) -> Eff (Local a :* e) ()
localModify :: (a -> a) -> Eff (Local a :* e) ()
localModify a -> a
f = (forall e' ans. Local a e' ans -> Op (a -> a) () e' ans)
-> (a -> a) -> Eff (Local a :* e) ()
forall (h :: * -> * -> *) e a b.
(h :? e) =>
(forall e' ans. h e' ans -> Op a b e' ans) -> a -> Eff e b
perform forall e' ans. Local a e' ans -> Op (a -> a) () e' ans
forall a e ans. Local a e ans -> Op (a -> a) () e ans
lmodify a -> a
f
{-# INLINE localRet #-}
localRet :: a -> (ans -> a -> b) -> Eff (Local a :* e) ans -> Eff e b
localRet :: a -> (ans -> a -> b) -> Eff (Local a :* e) ans -> Eff e b
localRet a
init ans -> a -> b
ret Eff (Local a :* e) ans
action
= (Context e -> Ctl b) -> Eff e b
forall e a. (Context e -> Ctl a) -> Eff e a
Eff (\Context e
ctx -> a -> (Marker b -> IORef a -> Ctl b) -> Ctl b
forall a b. a -> (Marker b -> IORef a -> Ctl b) -> Ctl b
unsafePromptIORef a
init ((Marker b -> IORef a -> Ctl b) -> Ctl b)
-> (Marker b -> IORef a -> Ctl b) -> Ctl b
forall a b. (a -> b) -> a -> b
$ \Marker b
m IORef a
r ->
do ans
x <- Context (Local a :* e) -> Eff (Local a :* e) ans -> Ctl ans
forall e a. Context e -> Eff e a -> Ctl a
under (Marker b
-> Local a e b
-> ContextT e e
-> Context e
-> Context (Local a :* e)
forall ans (h :: * -> * -> *) e' e.
Marker ans
-> h e' ans -> ContextT e e' -> Context e -> Context (h :* e)
CCons Marker b
m (IORef a -> Local a e b
forall a e ans. IORef a -> Local a e ans
Local IORef a
r) ContextT e e
forall e. ContextT e e
CTId Context e
ctx) Eff (Local a :* e) ans
action
a
y <- IO a -> Ctl a
forall a. IO a -> Ctl a
unsafeIO (IORef a -> IO a
forall a. IORef a -> IO a
readIORef IORef a
r)
b -> Ctl b
forall (m :: * -> *) a. Monad m => a -> m a
return (ans -> a -> b
ret ans
x a
y))
{-# INLINE local #-}
local :: a -> Eff (Local a :* e) ans -> Eff e ans
local :: a -> Eff (Local a :* e) ans -> Eff e ans
local a
init Eff (Local a :* e) ans
action
= a -> (ans -> a -> ans) -> Eff (Local a :* e) ans -> Eff e ans
forall a ans b e.
a -> (ans -> a -> b) -> Eff (Local a :* e) ans -> Eff e b
localRet a
init ans -> a -> ans
forall a b. a -> b -> a
const Eff (Local a :* e) ans
action
{-# INLINE handlerLocalRet #-}
handlerLocalRet :: a -> (ans -> a -> b) -> (h (Local a :* e) b) -> Eff (h :* e) ans -> Eff e b
handlerLocalRet :: a
-> (ans -> a -> b)
-> h (Local a :* e) b
-> Eff (h :* e) ans
-> Eff e b
handlerLocalRet a
init ans -> a -> b
ret h (Local a :* e) b
h Eff (h :* e) ans
action
= a -> Eff (Local a :* e) b -> Eff e b
forall a e ans. a -> Eff (Local a :* e) ans -> Eff e ans
local a
init (Eff (Local a :* e) b -> Eff e b)
-> Eff (Local a :* e) b -> Eff e b
forall a b. (a -> b) -> a -> b
$ (ans -> Eff (Local a :* e) b)
-> h (Local a :* e) b -> Eff (h :* e) ans -> Eff (Local a :* e) b
forall ans (h' :: * -> * -> *) e b (h :: * -> * -> *).
(ans -> Eff (h' :* e) b)
-> h (h' :* e) b -> Eff (h :* e) ans -> Eff (h' :* e) b
handlerHideRetEff (\ans
x -> do{ a
y <- Eff (Local a :* e) a
forall a e. Eff (Local a :* e) a
localGet; b -> Eff (Local a :* e) b
forall (m :: * -> *) a. Monad m => a -> m a
return (ans -> a -> b
ret ans
x a
y)}) h (Local a :* e) b
h Eff (h :* e) ans
action
{-# INLINE handlerLocal #-}
handlerLocal :: a -> (h (Local a :* e) ans) -> Eff (h :* e) ans -> Eff e ans
handlerLocal :: a -> h (Local a :* e) ans -> Eff (h :* e) ans -> Eff e ans
handlerLocal a
init h (Local a :* e) ans
h Eff (h :* e) ans
action
= a -> Eff (Local a :* e) ans -> Eff e ans
forall a e ans. a -> Eff (Local a :* e) ans -> Eff e ans
local a
init (h (Local a :* e) ans -> Eff (h :* e) ans -> Eff (Local a :* e) ans
forall (h :: * -> * -> *) (h' :: * -> * -> *) e ans.
h (h' :* e) ans -> Eff (h :* e) ans -> Eff (h' :* e) ans
handlerHide h (Local a :* e) ans
h Eff (h :* e) ans
action)