@@ -2,12 +2,15 @@ module Effectful.Interpreter
22 ( -- * Sending commands
33 send
44
5− -- * Interpretation
5+ -- * Handling effects
6+ , RunIn
7+
8+ -- ** Interpretation
69 , interpret
710 , interpretM
811 , interpretIO
912
10− -- * Reinterpretation
13+ -- ** Reinterpretation
1114 , reinterpret
1215 , reinterpretM
1316 , reinterpretIO
@@ -54,29 +57,36 @@ send op = readerEffectM $ \Interpreter{..} -> do
5457----------------------------------------
5558-- Interpretation
5659
60+-- | A function that runs 'Eff' computations in @m@ (usually a local 'Eff'
61+-- environment or 'IO').
62+type RunIn es m = forall r. Eff es r -> m r
63+
5764-- | Interpret a first order effect.
5865interpret
5966 :: (forall r es. HasCallStack => e (Eff es) r -> Eff baseEs r)
67+ -- ^ The effect handler
6068 -> Eff (e : baseEs) a
6169 -> Eff baseEs a
6270interpret interpreter m = unsafeEff $ \es -> do
6371 les <- forkEnv es
6472 runInterpreter es (Interpreter les $ \_ -> interpreter) m
6573
66−-- | Interpret a higher order effect with help of a natural transformation from
67−-- 'Eff' to 'Eff'.
74+-- | Interpret a higher order effect with help of a function running 'Eff'
75+-- computations in the local 'Eff' of an effect handler.
6876interpretM
69− :: (forall r es. HasCallStack => (forall t. Eff es t -> Eff baseEs t) -> e (Eff es) r -> Eff baseEs r)
77+ :: (forall r es. HasCallStack => RunIn es (Eff baseEs) -> e (Eff es) r -> Eff baseEs r)
78+ -- ^ The effect handler
7079 -> Eff (e : baseEs) a
7180 -> Eff baseEs a
7281interpretM interpreter m = unsafeEff $ \es -> do
7382 les <- forkEnv es
7483 runInterpreter es (Interpreter les $ \k -> interpreter $ unsafeEff_ . k) m
7584
76−-- | Interpret a higher order effect with help of a natural transformation from
77−-- 'Eff' to 'IO'.
85+-- | Interpret a higher order effect with help of a function running 'Eff'
86+-- computations in 'IO'.
7887interpretIO
79− :: (forall r es. HasCallStack => (forall t. Eff es t -> IO t) -> e (Eff es) r -> Eff baseEs r)
88+ :: (forall r es. HasCallStack => RunIn es IO -> e (Eff es) r -> Eff baseEs r)
89+ -- ^ The effect handler
8090 -> Eff (e : baseEs) a
8191 -> Eff baseEs a
8292interpretIO interpreter m = unsafeEff $ \es -> do
@@ -86,10 +96,12 @@ interpretIO interpreter m = unsafeEff $ \es -> do
8696----------------------------------------
8797-- Reinterpretation
8898
89−-- | Reinterpret local effects as a first order effect.
99+-- | Interpret a first order effect using local effects.
90100reinterpret
91101 :: (Eff localEs a -> Eff baseEs b)
102+ -- ^ Introduction of local effects
92103 -> (forall r es. HasCallStack => e (Eff es) r -> Eff localEs r)
104+ -- ^ The efect handler
93105 -> Eff (e : baseEs) a
94106 -> Eff baseEs b
95107reinterpret runLocal interpreter m = unsafeEff $ \es -> do
@@ -97,11 +109,13 @@ reinterpret runLocal interpreter m = unsafeEff $ \es -> do
97109 (`unEff` les0) . runLocal . unsafeEff $ \les -> do
98110 runInterpreter es (Interpreter les $ \_ -> interpreter) m
99111
100−-- | Reinterpret local effects as a higher order effect with help of a natural
101−-- transformation from 'Eff' to 'Eff'.
112+-- | Interpret a higher order effect using local effects with help of a function
113+-- running 'Eff' computations in the local 'Eff' of an effect handler.
102114reinterpretM
103115 :: (Eff localEs a -> Eff baseEs b)
104− -> (forall r es. HasCallStack => (forall t. Eff es t -> Eff localEs t) -> e (Eff es) r -> Eff localEs r)
116+ -- ^ Introduction of local effects
117+ -> (forall r es. HasCallStack => RunIn es (Eff localEs) -> e (Eff es) r -> Eff localEs r)
118+ -- ^ The effect handler
105119 -> Eff (e : baseEs) a
106120 -> Eff baseEs b
107121reinterpretM runLocal interpreter m = unsafeEff $ \es -> do
@@ -109,11 +123,13 @@ reinterpretM runLocal interpreter m = unsafeEff $ \es -> do
109123 (`unEff` les0) . runLocal . unsafeEff $ \les -> do
110124 runInterpreter es (Interpreter les $ \k -> interpreter $ unsafeEff_ . k) m
111125
112−-- | Reinterpret local effects as a higher order effect with help of a natural
113−-- transformation from 'Eff' to 'IO'.
126+-- | Interpret a higher order effect using local effects with help of a function
127+-- running 'Eff' computations in 'IO'.
114128reinterpretIO
115129 :: (Eff localEs a -> Eff baseEs b)
116− -> (forall r es. HasCallStack => (forall t. Eff es t -> IO t) -> e (Eff es) r -> Eff localEs r)
130+ -- ^ Introduction of local effects
131+ -> (forall r es. HasCallStack => RunIn es IO -> e (Eff es) r -> Eff localEs r)
132+ -- ^ The effect handler
117133 -> Eff (e : baseEs) a
118134 -> Eff baseEs b
119135reinterpretIO runLocal interpreter m = unsafeEff $ \es -> do