on master help sign in
Rename type variables used in the interpret family
commitc146d22b39e657835fdad04b7c6854d309eb0e76 authorAndrzej Rybczak <andrzej@rybczak.net> dateFri 2 Jul 2021, 19:11 (5 years ago) parent4537055
4 files changed+61−61
src/Effectful/Internal/Monad.hs+1−1 src/Effectful/Interpreter.hs+44−44 src/Effectful/State/Dynamic.hs+8−8 src/Effectful/Writer/Dynamic.hs+8−8
src/Effectful/Internal/Monad.hs+1−1
@@ -71,7 +71,7 @@ type role Eff nominal representational
7171-- @
7272--
7373-- Normally, a concrete list of effects is not used to parameterize 'Eff'.
74−-- Instead, the '(:>)' class is used to express constraints on the list of
74+-- Instead, the '(:>)' type class is used to express constraints on the list of
7575-- effects without coupling an operation to a concrete list of effects. For
7676-- example, the above example would more commonly be expressed with the
7777-- following type:
src/Effectful/Interpreter.hs+44−44
@@ -26,12 +26,12 @@ import Effectful.Internal.Monad
2626----------------------------------------
2727-- Interpreter
2828
29−data Interpreter (e :: Effect) = forall localEs. Interpreter
30− { _env :: Env localEs
31− , _interpret :: forall a es. HasCallStack
32− => RunIn es IO
33− -> e (Eff es) a
34− -> Eff localEs a
29+data Interpreter (e :: Effect) = forall handlerEs. Interpreter
30+ { _env :: Env handlerEs
31+ , _interpret :: forall a localEs. HasCallStack
32+ => RunIn localEs IO
33+ -> e (Eff localEs) a
34+ -> Eff handlerEs a
3535 }
3636
3737runInterpreter :: Env es -> Interpreter e -> Eff (e : es) a -> IO a
@@ -62,32 +62,32 @@ send op = readerEffectM $ \Interpreter{..} -> do
6262
6363-- | Interpret a first order effect.
6464interpret
65− :: (forall r es. HasCallStack => e (Eff es) r -> Eff baseEs r)
66− -- ^ The effect handler
67− -> Eff (e : baseEs) a
68− -> Eff baseEs a
65+ :: (forall r localEs. HasCallStack => e (Eff localEs) r -> Eff es r)
66+ -- ^ The effect handler.
67+ -> Eff (e : es) a
68+ -> Eff es a
6969interpret interpreter m = unsafeEff $ \es -> do
7070 les <- forkEnv es
7171 runInterpreter es (Interpreter les $ \_ -> interpreter) m
7272
73−-- | Interpret a higher order effect with help of a function running 'Eff'
74−-- operations in the local 'Eff' of an effect handler.
73+-- | Interpret a higher order effect with help of a function running local 'Eff'
74+-- operations in the context of an effect handler.
7575interpretM
76− :: (forall r es. HasCallStack => RunIn es (Eff baseEs) -> e (Eff es) r -> Eff baseEs r)
77− -- ^ The effect handler
78− -> Eff (e : baseEs) a
79− -> Eff baseEs a
76+ :: (forall r localEs. HasCallStack => RunIn localEs (Eff es) -> e (Eff localEs) r -> Eff es r)
77+ -- ^ The effect handler.
78+ -> Eff (e : es) a
79+ -> Eff es a
8080interpretM interpreter m = unsafeEff $ \es -> do
8181 les <- forkEnv es
8282 runInterpreter es (Interpreter les $ \k -> interpreter $ unsafeEff_ . k) m
8383
84−-- | Interpret a higher order effect with help of a function running 'Eff'
84+-- | Interpret a higher order effect with help of a function running local 'Eff'
8585-- operations in 'IO'.
8686interpretIO
87− :: (forall r es. HasCallStack => RunIn es IO -> e (Eff es) r -> Eff baseEs r)
88− -- ^ The effect handler
89− -> Eff (e : baseEs) a
90− -> Eff baseEs a
87+ :: (forall r localEs. HasCallStack => RunIn localEs IO -> e (Eff localEs) r -> Eff es r)
88+ -- ^ The effect handler.
89+ -> Eff (e : es) a
90+ -> Eff es a
9191interpretIO interpreter m = unsafeEff $ \es -> do
9292 les <- forkEnv es
9393 runInterpreter es (Interpreter les interpreter) m
@@ -95,42 +95,42 @@ interpretIO interpreter m = unsafeEff $ \es -> do
9595----------------------------------------
9696-- Reinterpretation
9797
98−-- | Interpret a first order effect using local effects.
98+-- | Interpret a first order effect using other effects.
9999reinterpret
100− :: (Eff localEs a -> Eff baseEs b)
101− -- ^ Introduction of local effects
102− -> (forall r es. HasCallStack => e (Eff es) r -> Eff localEs r)
103− -- ^ The effect handler
104− -> Eff (e : baseEs) a
105− -> Eff baseEs b
100+ :: (Eff handlerEs a -> Eff es b)
101+ -- ^ Introduction of effects encapsulated within the handler.
102+ -> (forall r localEs. HasCallStack => e (Eff localEs) r -> Eff handlerEs r)
103+ -- ^ The effect handler.
104+ -> Eff (e : es) a
105+ -> Eff es b
106106reinterpret runLocal interpreter m = unsafeEff $ \es -> do
107107 les0 <- forkEnv es
108108 (`unEff` les0) . runLocal . unsafeEff $ \les -> do
109109 runInterpreter es (Interpreter les $ \_ -> interpreter) m
110110
111−-- | Interpret a higher order effect using local effects with help of a function
112−-- running 'Eff' operations in the local 'Eff' of an effect handler.
111+-- | Interpret a higher order effect using other effects with help of a function
112+-- running local 'Eff' operations in the context of an effect handler.
113113reinterpretM
114− :: (Eff localEs a -> Eff baseEs b)
115− -- ^ Introduction of local effects
116− -> (forall r es. HasCallStack => RunIn es (Eff localEs) -> e (Eff es) r -> Eff localEs r)
117− -- ^ The effect handler
118− -> Eff (e : baseEs) a
119− -> Eff baseEs b
114+ :: (Eff handlerEs a -> Eff es b)
115+ -- ^ Introduction of effects encapsulated within the handler.
116+ -> (forall r localEs. HasCallStack => RunIn localEs (Eff handlerEs) -> e (Eff localEs) r -> Eff handlerEs r)
117+ -- ^ The effect handler.
118+ -> Eff (e : es) a
119+ -> Eff es b
120120reinterpretM runLocal interpreter m = unsafeEff $ \es -> do
121121 les0 <- forkEnv es
122122 (`unEff` les0) . runLocal . unsafeEff $ \les -> do
123123 runInterpreter es (Interpreter les $ \k -> interpreter $ unsafeEff_ . k) m
124124
125−-- | Interpret a higher order effect using local effects with help of a function
126−-- running 'Eff' operations in 'IO'.
125+-- | Interpret a higher order effect using other effects with help of a function
126+-- running local 'Eff' operations in 'IO'.
127127reinterpretIO
128− :: (Eff localEs a -> Eff baseEs b)
129− -- ^ Introduction of local effects
130− -> (forall r es. HasCallStack => RunIn es IO -> e (Eff es) r -> Eff localEs r)
131− -- ^ The effect handler
132− -> Eff (e : baseEs) a
133− -> Eff baseEs b
128+ :: (Eff handlerEs a -> Eff es b)
129+ -- ^ Introduction of effects encapsulated within the handler.
130+ -> (forall r localEs. HasCallStack => RunIn localEs IO -> e (Eff localEs) r -> Eff handlerEs r)
131+ -- ^ The effect handler.
132+ -> Eff (e : es) a
133+ -> Eff es b
134134reinterpretIO runLocal interpreter m = unsafeEff $ \es -> do
135135 les0 <- forkEnv es
136136 (`unEff` les0) . runLocal . unsafeEff $ \les -> do
src/Effectful/State/Dynamic.hs+8−8
@@ -61,10 +61,10 @@ execState :: s -> Eff (State s : es) a -> Eff es s
6161execState s0 = reinterpretM (SP.execState s0) statePure
6262
6363statePure
64− :: SP.State s :> localEs
65− => RunIn es (Eff localEs)
66− -> State s (Eff es) a
67− -> Eff localEs a
64+ :: SP.State s :> es
65+ => RunIn localEs (Eff es)
66+ -> State s (Eff localEs) a
67+ -> Eff es a
6868statePure run = \case
6969 Get -> SP.get
7070 Put s -> SP.put s
@@ -84,10 +84,10 @@ execStateMVar :: s -> Eff (State s : es) a -> Eff es s
8484execStateMVar s0 = reinterpretM (SM.execState s0) stateMVar
8585
8686stateMVar
87− :: SM.State s :> localEs
88− => (forall r. Eff es r -> Eff localEs r)
89− -> State s (Eff es) a
90− -> Eff localEs a
87+ :: SM.State s :> es
88+ => (forall r. Eff localEs r -> Eff es r)
89+ -> State s (Eff localEs) a
90+ -> Eff es a
9191stateMVar run = \case
9292 Get -> SM.get
9393 Put s -> SM.put s
src/Effectful/Writer/Dynamic.hs+8−8
@@ -34,10 +34,10 @@ execWriter :: Monoid w => Eff (Writer w : es) a -> Eff es w
3434execWriter = reinterpretM WP.execWriter writerPure
3535
3636writerPure
37− :: (WP.Writer w :> localEs, Monoid w)
38− => RunIn es (Eff localEs)
39− -> Writer w (Eff es) a
40− -> Eff localEs a
37+ :: (WP.Writer w :> es, Monoid w)
38+ => RunIn localEs (Eff es)
39+ -> Writer w (Eff localEs) a
40+ -> Eff es a
4141writerPure run = \case
4242 Tell w -> WP.tell w
4343 Listen m -> WP.listen (run m)
@@ -52,10 +52,10 @@ execWriterMVar :: Monoid w => Eff (Writer w : es) a -> Eff es w
5252execWriterMVar = reinterpretM WM.execWriter writerMVar
5353
5454writerMVar
55− :: (WM.Writer w :> localEs, Monoid w)
56− => RunIn es (Eff localEs)
57− -> Writer w (Eff es) a
58− -> Eff localEs a
55+ :: (WM.Writer w :> es, Monoid w)
56+ => RunIn localEs (Eff es)
57+ -> Writer w (Eff localEs) a
58+ -> Eff es a
5959writerMVar run = \case
6060 Tell w -> WM.tell w
6161 Listen m -> WM.listen (run m)