@@ -43,7 +43,7 @@ type role Env nominal
43-- of kind 'Effect'.
43-- of kind 'Effect'.
45-- Supports forking, i.e. introduction of local branches for encapsulation of
45-- Supports forking, i.e. introduction of local branches for encapsulation of
46−-- data specific to effect interpreters.
46+-- data specific to effect handlers.
48-- Offers very good performance characteristics:
48-- Offers very good performance characteristics:
@@ -150,10 +150,10 @@ newForkId (ForkIdGen ref) = do
151newtype Relinker i (e :: Effect) where
151newtype Relinker i (e :: Effect) where
153− :: ((forall es. Env es -> IO (Env es)) -> i e -> IO (i e))
153+ :: ((forall es. Env es -> IO (Env es)) -> handler e -> IO (handler e))
154− -> Relinker i e
154+ -> Relinker handler e
156−noRelinker :: Relinker i e
156+noRelinker :: Relinker handler e
157noRelinker = Relinker $ \_ -> pure
157noRelinker = Relinker $ \_ -> pure
159----------------------------------------
159----------------------------------------
@@ -238,7 +238,7 @@ copyForks es fs len = \case
239type EnvRefCache = IORef (IM.IntMap (IORef EnvRef))
239type EnvRefCache = IORef (IM.IntMap (IORef EnvRef))
241−-- | Relink local environments hiding in the interpreters.
241+-- | Relink local environments hiding in the handlers.
242relinkData
242relinkData
243 :: IORef EnvRef
243 :: IORef EnvRef
244 -> ForkIdGen
244 -> ForkIdGen
@@ -294,7 +294,7 @@ cloneEnvRef gref gen cache fid lref0 = do
295----------------------------------------
295----------------------------------------
297−-- | Create a local fork of the environment for interpreters.
297+-- | Create a local fork of the environment for handlers.
298forkEnv :: Env es -> IO (Env es)
298forkEnv :: Env es -> IO (Env es)
299forkEnv env@(Env NoFork gref gen) = do
299forkEnv env@(Env NoFork gref gen) = do
300 size <- sizeEnv env
300 size <- sizeEnv env
@@ -321,7 +321,7 @@ sizeEnv (Env (Forks _ baseIx lref _) _ _) = do
321{-# NOINLINE sizeEnv #-}
321{-# NOINLINE sizeEnv #-}
323-- | Extract a specific data type from the environment.
323-- | Extract a specific data type from the environment.
324−getEnv :: forall e es i. e :> es => Env es -> IO (i e)
324+getEnv :: forall e es handler. e :> es => Env es -> IO (handler e)
325getEnv env = do
325getEnv env = do
326 (i, es) <- getLocation @e env
326 (i, es) <- getLocation @e env
327 fromAny <$> readSmallArray es i
327 fromAny <$> readSmallArray es i
@@ -343,7 +343,7 @@ checkSizeEnv k (Env (Forks _ baseIx lref _) _ _) = do
343-- Extending and shrinking
343-- Extending and shrinking
345-- | Extend the environment with a new data type (in place).
345-- | Extend the environment with a new data type (in place).
346−unsafeConsEnv :: i e -> Relinker i e -> Env es -> IO (Env (e : es))
346+unsafeConsEnv :: handler e -> Relinker handler e -> Env es -> IO (Env (e : es))
347unsafeConsEnv e f (Env fork gref gen) = case fork of
347unsafeConsEnv e f (Env fork gref gen) = case fork of
348 NoFork -> do
348 NoFork -> do
349 extendEnvRef gref
349 extendEnvRef gref
@@ -402,20 +402,31 @@ unsafeTailEnv len (Env fork gref gen) = case fork of
402-- Data retrieval and update
402-- Data retrieval and update
404-- | Replace the data type in the environment with a new value (in place).
404-- | Replace the data type in the environment with a new value (in place).
405−unsafePutEnv :: forall e es i. e :> es => i e -> Env es -> IO ()
405+unsafePutEnv
406+ :: forall e es handler. e :> es
406unsafePutEnv e env = do
409unsafePutEnv e env = do
407 (i, es) <- getLocation @e env
410 (i, es) <- getLocation @e env
408 e `seq` writeSmallArray es i (toAny e)
411 e `seq` writeSmallArray es i (toAny e)
410-- | Modify the data type in the environment (in place).
413-- | Modify the data type in the environment (in place).
411−unsafeModifyEnv :: forall e es i. e :> es => (i e -> i e) -> Env es -> IO ()
414+unsafeModifyEnv
415+ :: forall e es handler. e :> es
416+ => (handler e -> handler e)
412unsafeModifyEnv f env = do
419unsafeModifyEnv f env = do
413 (i, es) <- getLocation @e env
420 (i, es) <- getLocation @e env
414 e <- f . fromAny <$> readSmallArray es i
421 e <- f . fromAny <$> readSmallArray es i
415 e `seq` writeSmallArray es i (toAny e)
422 e `seq` writeSmallArray es i (toAny e)
417-- | Modify the data type in the environment (in place) and return a value.
424-- | Modify the data type in the environment (in place) and return a value.
418−unsafeStateEnv :: forall e es i a. e :> es => (i e -> (a, i e)) -> Env es -> IO a
425+unsafeStateEnv
426+ :: forall e es handler a. e :> es
427+ => (handler e -> (a, handler e))
419unsafeStateEnv f env = do
430unsafeStateEnv f env = do
420 (i, es) <- getLocation @e env
431 (i, es) <- getLocation @e env
421 (a, e) <- f . fromAny <$> readSmallArray es i
432 (a, e) <- f . fromAny <$> readSmallArray es i
@@ -443,8 +454,8 @@ getLocation (Env fork ref _) = do
443 -- - Most application code has no access to forks, in which case we look at
454 -- - Most application code has no access to forks, in which case we look at
444 -- the global EnvRef.
455 -- the global EnvRef.
446− -- - Interpreters will most likely access the newest fork for reinterpretation
457+ -- - Effect handlers will most likely access the newest fork with handler
447− -- of effects that are there.
458+ -- specific effects for reinterpretation.
448 case fork of
459 case fork of
449 NoFork -> pure (ix n, es)
460 NoFork -> pure (ix n, es)
450 Forks _ baseIx lref forks -> do
461 Forks _ baseIx lref forks -> do