on master help sign in
Safer and more descriptive API for static dispatch
f749af5Andrzej Rybczak
effectful-core/src/Effectful/Dispatch/Dynamic.hs+2−2
@@ -49,7 +49,7 @@ interpret
49 -> Eff es a
49 -> Eff es a
50interpret handler m = unsafeEff $ \es -> do
50interpret handler m = unsafeEff $ \es -> do
51 les <- forkEnv es
51 les <- forkEnv es
52− (`unEff` es) $ runHandlerA (HandlerA les handler) m
52+ (`unEff` es) $ runHandler (HandlerA les handler) m
53
53
54-- | Interpret an effect using other effects.
54-- | Interpret an effect using other effects.
55reinterpret
55reinterpret
@@ -62,7 +62,7 @@ reinterpret
62reinterpret runHandlerEs handler m = unsafeEff $ \es -> do
62reinterpret runHandlerEs handler m = unsafeEff $ \es -> do
63 les0 <- forkEnv es
63 les0 <- forkEnv es
64 (`unEff` les0) . runHandlerEs . unsafeEff $ \les -> do
64 (`unEff` les0) . runHandlerEs . unsafeEff $ \les -> do
65− (`unEff` es) $ runHandlerA (HandlerA les handler) m
65+ (`unEff` es) $ runHandler (HandlerA les handler) m
66
66
67----------------------------------------
67----------------------------------------
68-- Unlifts
68-- Unlifts
effectful-core/src/Effectful/Dispatch/Static.hs+9−9
@@ -1,18 +1,18 @@
1module Effectful.Dispatch.Static
1module Effectful.Dispatch.Static
2 ( -- * Low level API
2 ( -- * Low level API
3− IdA(..)
3+ DataA(..)
4
4
5 -- ** Running
5 -- ** Running
6− , runEffect
6+ , runData
7− , evalEffect
7+ , evalData
8− , execEffect
8+ , execData
9
9
10 -- ** Modification
10 -- ** Modification
11− , getEffect
11+ , getData
12− , putEffect
12+ , putData
13− , stateEffect
13+ , stateData
14− , stateEffectM
14+ , stateDataM
15− , localEffect
15+ , localData
16
16
17 -- ** Unlifts
17 -- ** Unlifts
18 , seqUnliftIO
18 , seqUnliftIO
effectful-core/src/Effectful/Error.hs+3−3
@@ -102,7 +102,7 @@ runError
102runError m = unsafeEff $ \es0 -> mask $ \release -> do
102runError m = unsafeEff $ \es0 -> mask $ \release -> do
103 eid <- newErrorId
103 eid <- newErrorId
104 size0 <- sizeEnv es0
104 size0 <- sizeEnv es0
105− es <- unsafeConsEnv (IdA (Error @e eid)) noRelinker es0
105+ es <- unsafeConsEnv (DataA (Error @e eid)) noRelinker es0
106 r <- tryErrorIO release eid es `onException` unsafeTailEnv size0 es
106 r <- tryErrorIO release eid es `onException` unsafeTailEnv size0 es
107 unsafeTailEnv size0 es
107 unsafeTailEnv size0 es
108 pure r
108 pure r
@@ -119,7 +119,7 @@ throwError
119 -- ^ The error.
119 -- ^ The error.
120 -> Eff es a
120 -> Eff es a
121throwError e = unsafeEff $ \es -> do
121throwError e = unsafeEff $ \es -> do
122− IdA (Error eid) <- getEnv @(Error e) es
122+ DataA (Error eid) <- getEnv @(Error e) es
123 throwIO $ ErrorEx eid callStack e
123 throwIO $ ErrorEx eid callStack e
124
124
125-- | Handle an error of type @e@.
125-- | Handle an error of type @e@.
@@ -131,7 +131,7 @@ catchError
131 -- ^ A handler for errors in the inner computation.
131 -- ^ A handler for errors in the inner computation.
132 -> Eff es a
132 -> Eff es a
133catchError m handler = unsafeEff $ \es -> do
133catchError m handler = unsafeEff $ \es -> do
134− IdA (Error eid) <- getEnv @(Error e) es
134+ DataA (Error eid) <- getEnv @(Error e) es
135 size <- sizeEnv es
135 size <- sizeEnv es
136 catchErrorIO eid (unEff m es) $ \cs e -> do
136 catchErrorIO eid (unEff m es) $ \cs e -> do
137 checkSizeEnv size es
137 checkSizeEnv size es
effectful-core/src/Effectful/Internal/Effect.hs+3−3
@@ -8,7 +8,7 @@
8module Effectful.Internal.Effect
8module Effectful.Internal.Effect
9 ( Effect
9 ( Effect
10 , (:>)(..)
10 , (:>)(..)
11− , IdA(..)
11+ , DataA(..)
12
12
13 -- * Utils
13 -- * Utils
14 , SuffixOf
14 , SuffixOf
@@ -24,8 +24,8 @@ import GHC.TypeLits
24type Effect = (Type -> Type) -> Type -> Type
24type Effect = (Type -> Type) -> Type -> Type
25
25
26-- | An adapter for statically dispatched effects.
26-- | An adapter for statically dispatched effects.
27−newtype IdA :: Effect -> Type where
27+newtype DataA :: Effect -> Type where
28− IdA :: (forall m r. e m r) -> IdA e
28+ DataA :: (forall m r. e m r) -> DataA e
29
29
30-- | A constraint that requires that a particular effect @e@ is a member of the
30-- | A constraint that requires that a particular effect @e@ is a member of the
31-- type-level list @es@. This is used to parameterize an 'Effectful.Monad.Eff'
31-- type-level list @es@. This is used to parameterize an 'Effectful.Monad.Eff'
effectful-core/src/Effectful/Internal/Monad.hs+31−31
@@ -44,7 +44,7 @@ module Effectful.Internal.Monad
44 , EffectHandler
44 , EffectHandler
45 , LocalEnv(..)
45 , LocalEnv(..)
46 , HandlerA(..)
46 , HandlerA(..)
47− , runHandlerA
47+ , runHandler
48
48
49 -- *** Sending operations
49 -- *** Sending operations
50 , send
50 , send
@@ -52,16 +52,16 @@ module Effectful.Internal.Monad
52 -- ** Primitive
52 -- ** Primitive
53
53
54 -- *** Running
54 -- *** Running
55− , runEffect
55+ , runData
56− , evalEffect
56+ , evalData
57− , execEffect
57+ , execData
58
58
59 -- *** Modification
59 -- *** Modification
60− , getEffect
60+ , getData
61− , putEffect
61+ , putData
62− , stateEffect
62+ , stateData
63− , stateEffectM
63+ , stateDataM
64− , localEffect
64+ , localData
65 ) where
65 ) where
66
66
67import Control.Applicative (liftA2)
67import Control.Applicative (liftA2)
@@ -151,12 +151,12 @@ unsafeEff_ m = unsafeEff $ \_ -> m
151-- | Get the current 'UnliftStrategy'.
151-- | Get the current 'UnliftStrategy'.
152unliftStrategy :: IOE :> es => Eff es UnliftStrategy
152unliftStrategy :: IOE :> es => Eff es UnliftStrategy
153unliftStrategy = do
153unliftStrategy = do
154− IdA (IOE unlift) <- getEffect
154+ DataA (IOE unlift) <- getData
155 pure unlift
155 pure unlift
156
156
157-- | Locally override the 'UnliftStrategy' with the given value.
157-- | Locally override the 'UnliftStrategy' with the given value.
158withUnliftStrategy :: IOE :> es => UnliftStrategy -> Eff es a -> Eff es a
158withUnliftStrategy :: IOE :> es => UnliftStrategy -> Eff es a -> Eff es a
159−withUnliftStrategy unlift = localEffect $ \_ -> IdA (IOE unlift)
159+withUnliftStrategy unlift = localData $ \_ -> DataA (IOE unlift)
160
160
161-- | Create an unlifting function with the current 'UnliftStrategy'.
161-- | Create an unlifting function with the current 'UnliftStrategy'.
162--
162--
@@ -272,7 +272,7 @@ newtype IOE :: Effect where
272--
272--
273-- For running pure computations see 'runPureEff'.
273-- For running pure computations see 'runPureEff'.
274runEff :: Eff '[IOE] a -> IO a
274runEff :: Eff '[IOE] a -> IO a
275−runEff m = unEff (evalEffect (IdA (IOE SeqUnlift)) m) =<< emptyEnv
275+runEff m = unEff (evalData (DataA (IOE SeqUnlift)) m) =<< emptyEnv
276
276
277instance IOE :> es => MonadIO (Eff es) where
277instance IOE :> es => MonadIO (Eff es) where
278 liftIO = unsafeEff_
278 liftIO = unsafeEff_
@@ -302,7 +302,7 @@ data Prim :: Effect where
302
302
303-- | Run an 'Eff' computation with primitive state-transformer actions.
303-- | Run an 'Eff' computation with primitive state-transformer actions.
304runPrim :: IOE :> es => Eff (Prim : es) a -> Eff es a
304runPrim :: IOE :> es => Eff (Prim : es) a -> Eff es a
305−runPrim = evalEffect (IdA Prim)
305+runPrim = evalData (DataA Prim)
306
306
307instance Prim :> es => PrimMonad (Eff es) where
307instance Prim :> es => PrimMonad (Eff es) where
308 type PrimState (Eff es) = RealWorld
308 type PrimState (Eff es) = RealWorld
@@ -338,8 +338,8 @@ data HandlerA :: Effect -> Type where
338 HandlerA :: !(Env es) -> !(EffectHandler e es) -> HandlerA e
338 HandlerA :: !(Env es) -> !(EffectHandler e es) -> HandlerA e
339
339
340-- | Run the effect with the given handler.
340-- | Run the effect with the given handler.
341−runHandlerA :: HandlerA e -> Eff (e : es) a -> Eff es a
341+runHandler :: HandlerA e -> Eff (e : es) a -> Eff es a
342−runHandlerA e m = unsafeEff $ \es0 -> do
342+runHandler e m = unsafeEff $ \es0 -> do
343 size0 <- sizeEnv es0
343 size0 <- sizeEnv es0
344 E.bracket (unsafeConsEnv e relinker es0)
344 E.bracket (unsafeConsEnv e relinker es0)
345 (unsafeTailEnv size0)
345 (unsafeTailEnv size0)
@@ -359,44 +359,44 @@ send op = unsafeEff $ \es -> do
359----------------------------------------
359----------------------------------------
360-- Helpers
360-- Helpers
361
361
362−runEffect :: adapter e -> Eff (e : es) a -> Eff es (a, adapter e)
362+runData :: DataA e -> Eff (e : es) a -> Eff es (a, DataA e)
363−runEffect e0 m = unsafeEff $ \es0 -> do
363+runData e0 m = unsafeEff $ \es0 -> do
364 size0 <- sizeEnv es0
364 size0 <- sizeEnv es0
365 E.bracket (unsafeConsEnv e0 noRelinker es0)
365 E.bracket (unsafeConsEnv e0 noRelinker es0)
366 (unsafeTailEnv size0)
366 (unsafeTailEnv size0)
367 (\es -> (,) <$> unEff m es <*> getEnv es)
367 (\es -> (,) <$> unEff m es <*> getEnv es)
368
368
369−evalEffect :: adapter e -> Eff (e : es) a -> Eff es a
369+evalData :: DataA e -> Eff (e : es) a -> Eff es a
370−evalEffect e m = unsafeEff $ \es0 -> do
370+evalData e m = unsafeEff $ \es0 -> do
371 size0 <- sizeEnv es0
371 size0 <- sizeEnv es0
372 E.bracket (unsafeConsEnv e noRelinker es0)
372 E.bracket (unsafeConsEnv e noRelinker es0)
373 (unsafeTailEnv size0)
373 (unsafeTailEnv size0)
374 (\es -> unEff m es)
374 (\es -> unEff m es)
375
375
376−execEffect :: adapter e -> Eff (e : es) a -> Eff es (adapter e)
376+execData :: DataA e -> Eff (e : es) a -> Eff es (DataA e)
377−execEffect e0 m = unsafeEff $ \es0 -> do
377+execData e0 m = unsafeEff $ \es0 -> do
378 size0 <- sizeEnv es0
378 size0 <- sizeEnv es0
379 E.bracket (unsafeConsEnv e0 noRelinker es0)
379 E.bracket (unsafeConsEnv e0 noRelinker es0)
380 (unsafeTailEnv size0)
380 (unsafeTailEnv size0)
381 (\es -> unEff m es *> getEnv es)
381 (\es -> unEff m es *> getEnv es)
382
382
383−getEffect :: e :> es => Eff es (adapter e)
383+getData :: e :> es => Eff es (DataA e)
384−getEffect = unsafeEff $ \es -> getEnv es
384+getData = unsafeEff $ \es -> getEnv es
385
385
386−putEffect :: e :> es => adapter e -> Eff es ()
386+putData :: e :> es => DataA e -> Eff es ()
387−putEffect e = unsafeEff $ \es -> putEnv es e
387+putData e = unsafeEff $ \es -> putEnv es e
388
388
389−stateEffect :: e :> es => (adapter e -> (a, adapter e)) -> Eff es a
389+stateData :: e :> es => (DataA e -> (a, DataA e)) -> Eff es a
390−stateEffect f = unsafeEff $ \es -> stateEnv es f
390+stateData f = unsafeEff $ \es -> stateEnv es f
391
391
392−stateEffectM :: e :> es => (adapter e -> Eff es (a, adapter e)) -> Eff es a
392+stateDataM :: e :> es => (DataA e -> Eff es (a, DataA e)) -> Eff es a
393−stateEffectM f = unsafeEff $ \es -> E.mask $ \release -> do
393+stateDataM f = unsafeEff $ \es -> E.mask $ \release -> do
394 (a, e) <- (\e -> release $ unEff (f e) es) =<< getEnv es
394 (a, e) <- (\e -> release $ unEff (f e) es) =<< getEnv es
395 putEnv es e
395 putEnv es e
396 pure a
396 pure a
397
397
398−localEffect :: e :> es => (adapter e -> adapter e) -> Eff es a -> Eff es a
398+localData :: e :> es => (DataA e -> DataA e) -> Eff es a -> Eff es a
399−localEffect f m = unsafeEff $ \es -> do
399+localData f m = unsafeEff $ \es -> do
400 E.bracket (stateEnv es $ \e -> (e, f e))
400 E.bracket (stateEnv es $ \e -> (e, f e))
401 (\e -> putEnv es e)
401 (\e -> putEnv es e)
402 (\_ -> unEff m es)
402 (\_ -> unEff m es)
effectful-core/src/Effectful/Reader.hs+3−3
@@ -20,12 +20,12 @@ runReader
20 :: r -- ^ An initial environment.
20 :: r -- ^ An initial environment.
21 -> Eff (Reader r : es) a
21 -> Eff (Reader r : es) a
22 -> Eff es a
22 -> Eff es a
23−runReader r = evalEffect (IdA (Reader r))
23+runReader r = evalData (DataA (Reader r))
24
24
25-- | Fetch the value of the environment.
25-- | Fetch the value of the environment.
26ask :: Reader r :> es => Eff es r
26ask :: Reader r :> es => Eff es r
27ask = do
27ask = do
28− IdA (Reader r) <- getEffect
28+ DataA (Reader r) <- getData
29 pure r
29 pure r
30
30
31-- | Retrieve a function of the current environment.
31-- | Retrieve a function of the current environment.
@@ -46,4 +46,4 @@ local
46 => (r -> r) -- ^ The function to modify the environment.
46 => (r -> r) -- ^ The function to modify the environment.
47 -> Eff es a
47 -> Eff es a
48 -> Eff es a
48 -> Eff es a
49−local f = localEffect $ \(IdA (Reader r)) -> IdA (Reader (f r))
49+local f = localData $ \(DataA (Reader r)) -> DataA (Reader (f r))
effectful-core/src/Effectful/State/Local.hs+8−8
@@ -52,7 +52,7 @@ runState
52 -> Eff (State s : es) a
52 -> Eff (State s : es) a
53 -> Eff es (a, s)
53 -> Eff es (a, s)
54runState s0 m = do
54runState s0 m = do
55− (a, IdA (State s)) <- runEffect (IdA (State s0)) m
55+ (a, DataA (State s)) <- runData (DataA (State s0)) m
56 pure (a, s)
56 pure (a, s)
57
57
58-- | Run a 'State' effect with the given initial state and return the final
58-- | Run a 'State' effect with the given initial state and return the final
@@ -61,7 +61,7 @@ evalState
61 :: s -- ^ An initial state.
61 :: s -- ^ An initial state.
62 -> Eff (State s : es) a
62 -> Eff (State s : es) a
63 -> Eff es a -- ^ A return value.
63 -> Eff es a -- ^ A return value.
64−evalState s = evalEffect (IdA (State s))
64+evalState s = evalData (DataA (State s))
65
65
66-- | Run a 'State' effect with the given initial state and return the final
66-- | Run a 'State' effect with the given initial state and return the final
67-- state, discarding the final value.
67-- state, discarding the final value.
@@ -70,13 +70,13 @@ execState
70 -> Eff (State s : es) a
70 -> Eff (State s : es) a
71 -> Eff es s
71 -> Eff es s
72execState s0 m = do
72execState s0 m = do
73− IdA (State s) <- execEffect (IdA (State s0)) m
73+ DataA (State s) <- execData (DataA (State s0)) m
74 pure s
74 pure s
75
75
76-- | Fetch the current value of the state.
76-- | Fetch the current value of the state.
77get :: State s :> es => Eff es s
77get :: State s :> es => Eff es s
78get = do
78get = do
79− IdA (State s) <- getEffect
79+ DataA (State s) <- getData
80 pure s
80 pure s
81
81
82-- | Get a function of the current state.
82-- | Get a function of the current state.
@@ -90,14 +90,14 @@ gets f = f <$> get
90
90
91-- | Set the current state to the given value.
91-- | Set the current state to the given value.
92put :: State s :> es => s -> Eff es ()
92put :: State s :> es => s -> Eff es ()
93−put s = putEffect (IdA (State s))
93+put s = putData (DataA (State s))
94
94
95-- | Apply the function to the current state and return a value.
95-- | Apply the function to the current state and return a value.
96state
96state
97 :: State s :> es
97 :: State s :> es
98 => (s -> (a, s)) -- ^ The function to modify the state.
98 => (s -> (a, s)) -- ^ The function to modify the state.
99 -> Eff es a
99 -> Eff es a
100−state f = stateEffect $ \(IdA (State s0)) -> let (a, s) = f s0 in (a, IdA (State s))
100+state f = stateData $ \(DataA (State s0)) -> let (a, s) = f s0 in (a, DataA (State s))
101
101
102-- | Apply the function to the current state.
102-- | Apply the function to the current state.
103--
103--
@@ -113,9 +113,9 @@ stateM
113 :: State s :> es
113 :: State s :> es
114 => (s -> Eff es (a, s)) -- ^ The function to modify the state.
114 => (s -> Eff es (a, s)) -- ^ The function to modify the state.
115 -> Eff es a
115 -> Eff es a
116−stateM f = stateEffectM $ \(IdA (State s0)) -> do
116+stateM f = stateDataM $ \(DataA (State s0)) -> do
117 (a, s) <- f s0
117 (a, s) <- f s0
118− pure (a, IdA (State s))
118+ pure (a, DataA (State s))
119
119
120-- | Apply the monadic function to the current state.
120-- | Apply the monadic function to the current state.
121--
121--
effectful-core/src/Effectful/State/Shared.hs+7−7
@@ -52,7 +52,7 @@ newtype State s :: Effect where
52runState :: s -> Eff (State s : es) a -> Eff es (a, s)
52runState :: s -> Eff (State s : es) a -> Eff es (a, s)
53runState s m = do
53runState s m = do
54 v <- unsafeEff_ $ newMVar s
54 v <- unsafeEff_ $ newMVar s
55− a <- evalEffect (IdA (State v)) m
55+ a <- evalData (DataA (State v)) m
56 (a, ) <$> unsafeEff_ (readMVar v)
56 (a, ) <$> unsafeEff_ (readMVar v)
57
57
58-- | Run a 'State' effect with the given initial state and return the final
58-- | Run a 'State' effect with the given initial state and return the final
@@ -60,20 +60,20 @@ runState s m = do
60evalState :: s -> Eff (State s : es) a -> Eff es a
60evalState :: s -> Eff (State s : es) a -> Eff es a
61evalState s m = do
61evalState s m = do
62 v <- unsafeEff_ $ newMVar s
62 v <- unsafeEff_ $ newMVar s
63− evalEffect (IdA (State v)) m
63+ evalData (DataA (State v)) m
64
64
65-- | Run a 'State' effect with the given initial state and return the final
65-- | Run a 'State' effect with the given initial state and return the final
66-- state, discarding the final value.
66-- state, discarding the final value.
67execState :: s -> Eff (State s : es) a -> Eff es s
67execState :: s -> Eff (State s : es) a -> Eff es s
68execState s m = do
68execState s m = do
69 v <- unsafeEff_ $ newMVar s
69 v <- unsafeEff_ $ newMVar s
70− _ <- evalEffect (IdA (State v)) m
70+ _ <- evalData (DataA (State v)) m
71 unsafeEff_ $ readMVar v
71 unsafeEff_ $ readMVar v
72
72
73-- | Fetch the current value of the state.
73-- | Fetch the current value of the state.
74get :: State s :> es => Eff es s
74get :: State s :> es => Eff es s
75get = unsafeEff $ \es -> do
75get = unsafeEff $ \es -> do
76− IdA (State v) <- getEnv es
76+ DataA (State v) <- getEnv es
77 readMVar v
77 readMVar v
78
78
79-- | Get a function of the current state.
79-- | Get a function of the current state.
@@ -85,7 +85,7 @@ gets f = f <$> get
85-- | Set the current state to the given value.
85-- | Set the current state to the given value.
86put :: State s :> es => s -> Eff es ()
86put :: State s :> es => s -> Eff es ()
87put s = unsafeEff $ \es -> do
87put s = unsafeEff $ \es -> do
88− IdA (State v) <- getEnv es
88+ DataA (State v) <- getEnv es
89 modifyMVar_ v $ \_ -> s `seq` pure s
89 modifyMVar_ v $ \_ -> s `seq` pure s
90
90
91-- | Apply the function to the current state and return a value.
91-- | Apply the function to the current state and return a value.
@@ -93,7 +93,7 @@ put s = unsafeEff $ \es -> do
93-- /Note:/ this function gets an exclusive access to the state for its duration.
93-- /Note:/ this function gets an exclusive access to the state for its duration.
94state :: State s :> es => (s -> (a, s)) -> Eff es a
94state :: State s :> es => (s -> (a, s)) -> Eff es a
95state f = unsafeEff $ \es -> do
95state f = unsafeEff $ \es -> do
96− IdA (State v) <- getEnv es
96+ DataA (State v) <- getEnv es
97 modifyMVar v $ \s0 -> let (a, s) = f s0 in s `seq` pure (s, a)
97 modifyMVar v $ \s0 -> let (a, s) = f s0 in s `seq` pure (s, a)
98
98
99-- | Apply the function to the current state.
99-- | Apply the function to the current state.
@@ -109,7 +109,7 @@ modify f = state (\s -> ((), f s))
109-- /Note:/ this function gets an exclusive access to the state for its duration.
109-- /Note:/ this function gets an exclusive access to the state for its duration.
110stateM :: State s :> es => (s -> Eff es (a, s)) -> Eff es a
110stateM :: State s :> es => (s -> Eff es (a, s)) -> Eff es a
111stateM f = unsafeEff $ \es -> do
111stateM f = unsafeEff $ \es -> do
112− IdA (State v) <- getEnv es
112+ DataA (State v) <- getEnv es
113 modifyMVar v $ \s0 -> do
113 modifyMVar v $ \s0 -> do
114 (a, s) <- unEff (f s0) es
114 (a, s) <- unEff (f s0) es
115 s `seq` pure (s, a)
115 s `seq` pure (s, a)
effectful-core/src/Effectful/Writer/Local.hs+5−5
@@ -38,19 +38,19 @@ newtype Writer w :: Effect where
38-- output.
38-- output.
39runWriter :: Monoid w => Eff (Writer w : es) a -> Eff es (a, w)
39runWriter :: Monoid w => Eff (Writer w : es) a -> Eff es (a, w)
40runWriter m = do
40runWriter m = do
41− (a, IdA (Writer w)) <- runEffect (IdA (Writer mempty)) m
41+ (a, DataA (Writer w)) <- runData (DataA (Writer mempty)) m
42 pure (a, w)
42 pure (a, w)
43
43
44-- | Run a 'Writer' effect and return the final output, discarding the final
44-- | Run a 'Writer' effect and return the final output, discarding the final
45-- value.
45-- value.
46execWriter :: Monoid w => Eff (Writer w : es) a -> Eff es w
46execWriter :: Monoid w => Eff (Writer w : es) a -> Eff es w
47execWriter m = do
47execWriter m = do
48− IdA (Writer w) <- execEffect (IdA (Writer mempty)) m
48+ DataA (Writer w) <- execData (DataA (Writer mempty)) m
49 pure w
49 pure w
50
50
51-- | Append the given output to the overall output of the 'Writer'.
51-- | Append the given output to the overall output of the 'Writer'.
52tell :: (Writer w :> es, Monoid w) => w -> Eff es ()
52tell :: (Writer w :> es, Monoid w) => w -> Eff es ()
53−tell w = stateEffect $ \(IdA (Writer w0)) -> ((), IdA (Writer (w0 <> w)))
53+tell w = stateData $ \(DataA (Writer w0)) -> ((), DataA (Writer (w0 <> w)))
54
54
55-- | Execute an action and append its output to the overall output of the
55-- | Execute an action and append its output to the overall output of the
56-- 'Writer'.
56-- 'Writer'.
@@ -71,13 +71,13 @@ tell w = stateEffect $ \(IdA (Writer w0)) -> ((), IdA (Writer (w0 <> w)))
71-- "Hi there!"
71-- "Hi there!"
72listen :: (Writer w :> es, Monoid w) => Eff es a -> Eff es (a, w)
72listen :: (Writer w :> es, Monoid w) => Eff es a -> Eff es (a, w)
73listen m = unsafeEff $ \es -> mask $ \restore -> do
73listen m = unsafeEff $ \es -> mask $ \restore -> do
74− w0 <- stateEnv es $ \(IdA (Writer w)) -> (w, IdA (Writer mempty))
74+ w0 <- stateEnv es $ \(DataA (Writer w)) -> (w, DataA (Writer mempty))
75 a <- restore (unEff m es) `onException` merge es w0
75 a <- restore (unEff m es) `onException` merge es w0
76 (a, ) <$> merge es w0
76 (a, ) <$> merge es w0
77 where
77 where
78 merge es w0 =
78 merge es w0 =
79 -- If an exception is thrown, restore w0 and keep parts of w1.
79 -- If an exception is thrown, restore w0 and keep parts of w1.
80− stateEnv es $ \(IdA (Writer w1)) -> (w1, IdA (Writer (w0 <> w1)))
80+ stateEnv es $ \(DataA (Writer w1)) -> (w1, DataA (Writer (w0 <> w1)))
81
81
82-- | Execute an action and append its output to the overall output of the
82-- | Execute an action and append its output to the overall output of the
83-- 'Writer', then return the final value along with a function of the recorded
83-- 'Writer', then return the final value along with a function of the recorded
effectful-core/src/Effectful/Writer/Shared.hs+5−5
@@ -39,7 +39,7 @@ newtype Writer w :: Effect where
39runWriter :: Monoid w => Eff (Writer w : es) a -> Eff es (a, w)
39runWriter :: Monoid w => Eff (Writer w : es) a -> Eff es (a, w)
40runWriter m = do
40runWriter m = do
41 v <- unsafeEff_ $ newMVar mempty
41 v <- unsafeEff_ $ newMVar mempty
42− a <- evalEffect (IdA (Writer v)) m
42+ a <- evalData (DataA (Writer v)) m
43 (a, ) <$> unsafeEff_ (readMVar v)
43 (a, ) <$> unsafeEff_ (readMVar v)
44
44
45-- | Run a 'Writer' effect and return the final output, discarding the final
45-- | Run a 'Writer' effect and return the final output, discarding the final
@@ -47,13 +47,13 @@ runWriter m = do
47execWriter :: Monoid w => Eff (Writer w : es) a -> Eff es w
47execWriter :: Monoid w => Eff (Writer w : es) a -> Eff es w
48execWriter m = do
48execWriter m = do
49 v <- unsafeEff_ $ newMVar mempty
49 v <- unsafeEff_ $ newMVar mempty
50− _ <- evalEffect (IdA (Writer v)) m
50+ _ <- evalData (DataA (Writer v)) m
51 unsafeEff_ $ readMVar v
51 unsafeEff_ $ readMVar v
52
52
53-- | Append the given output to the overall output of the 'Writer'.
53-- | Append the given output to the overall output of the 'Writer'.
54tell :: (Writer w :> es, Monoid w) => w -> Eff es ()
54tell :: (Writer w :> es, Monoid w) => w -> Eff es ()
55tell w1 = unsafeEff $ \es -> do
55tell w1 = unsafeEff $ \es -> do
56− IdA (Writer v) <- getEnv es
56+ DataA (Writer v) <- getEnv es
57 modifyMVar_ v $ \w0 -> let w = w0 <> w1 in w `seq` pure w
57 modifyMVar_ v $ \w0 -> let w = w0 <> w1 in w `seq` pure w
58
58
59-- | Execute an action and append its output to the overall output of the
59-- | Execute an action and append its output to the overall output of the
@@ -81,14 +81,14 @@ listen m = unsafeEff $ \es -> do
81 uninterruptibleMask $ \restore -> do
81 uninterruptibleMask $ \restore -> do
82 v1 <- newMVar mempty
82 v1 <- newMVar mempty
83 -- Replace thread local MVar with a fresh one for isolated listening.
83 -- Replace thread local MVar with a fresh one for isolated listening.
84− v0 <- stateEnv es $ \(IdA (Writer v)) -> (v, IdA (Writer v1))
84+ v0 <- stateEnv es $ \(DataA (Writer v)) -> (v, DataA (Writer v1))
85 a <- restore (unEff m es) `onException` merge es v0 v1
85 a <- restore (unEff m es) `onException` merge es v0 v1
86 (a, ) <$> merge es v0 v1
86 (a, ) <$> merge es v0 v1
87 where
87 where
88 -- Merge results accumulated in the local MVar with the mainline. If an
88 -- Merge results accumulated in the local MVar with the mainline. If an
89 -- exception was received while listening, merge results recorded so far.
89 -- exception was received while listening, merge results recorded so far.
90 merge es v0 v1 = do
90 merge es v0 v1 = do
91− putEnv es $ IdA (Writer v0)
91+ putEnv es $ DataA (Writer v0)
92 w1 <- readMVar v1
92 w1 <- readMVar v1
93 modifyMVar_ v0 $ \w0 -> let w = w0 <> w1 in w `seq` pure w
93 modifyMVar_ v0 $ \w0 -> let w = w0 <> w1 in w `seq` pure w
94 pure w1
94 pure w1
effectful/src/Effectful/Concurrent/Effect.hs+1−1
@@ -72,7 +72,7 @@ data Concurrent :: Effect where
72
72
73-- | Run the 'Concurrent' effect.
73-- | Run the 'Concurrent' effect.
74runConcurrent :: IOE :> es => Eff (Concurrent : es) a -> Eff es a
74runConcurrent :: IOE :> es => Eff (Concurrent : es) a -> Eff es a
75−runConcurrent = evalEffect (IdA Concurrent)
75+runConcurrent = evalData (DataA Concurrent)
76
76
77-- $setup
77-- $setup
78-- >>> import Effectful.Concurrent
78-- >>> import Effectful.Concurrent
effectful/src/Effectful/Environment.hs+1−1
@@ -28,7 +28,7 @@ data Environment :: Effect where
28
28
29-- | Run the 'Environment' effect.
29-- | Run the 'Environment' effect.
30runEnvironment :: IOE :> es => Eff (Environment : es) a -> Eff es a
30runEnvironment :: IOE :> es => Eff (Environment : es) a -> Eff es a
31−runEnvironment = evalEffect (IdA Environment)
31+runEnvironment = evalData (DataA Environment)
32
32
33-- | Lifted 'E.getArgs'.
33-- | Lifted 'E.getArgs'.
34getArgs :: Environment :> es => Eff es [String]
34getArgs :: Environment :> es => Eff es [String]
effectful/src/Effectful/FileSystem.hs+1−1
@@ -100,7 +100,7 @@ data FileSystem :: Effect where
100
100
101-- | Run the 'FileSystem' effect.
101-- | Run the 'FileSystem' effect.
102runFileSystem :: IOE :> es => Eff (FileSystem : es) a -> Eff es a
102runFileSystem :: IOE :> es => Eff (FileSystem : es) a -> Eff es a
103−runFileSystem = evalEffect (IdA FileSystem)
103+runFileSystem = evalData (DataA FileSystem)
104
104
105----------------------------------------
105----------------------------------------
106-- Actions on directories
106-- Actions on directories
effectful/src/Effectful/FileSystem/Effect.hs+1−1
@@ -12,4 +12,4 @@ data FileSystem :: Effect where
12
12
13-- | Run the 'FileSystem' effect.
13-- | Run the 'FileSystem' effect.
14runFileSystem :: IOE :> es => Eff (FileSystem : es) a -> Eff es a
14runFileSystem :: IOE :> es => Eff (FileSystem : es) a -> Eff es a
15−runFileSystem = evalEffect (IdA FileSystem)
15+runFileSystem = evalData (DataA FileSystem)
effectful/src/Effectful/Process.hs+1−1
@@ -58,7 +58,7 @@ data Process :: Effect where
58 Process :: Process m r
58 Process :: Process m r
59
59
60runProcess :: IOE :> es => Eff (Process : es) a -> Eff es a
60runProcess :: IOE :> es => Eff (Process : es) a -> Eff es a
61−runProcess = evalEffect (IdA Process)
61+runProcess = evalData (DataA Process)
62
62
63----------------------------------------
63----------------------------------------
64-- Running sub-processes
64-- Running sub-processes
effectful/src/Effectful/Resource.hs+4−4
@@ -37,7 +37,7 @@ runResource m = unsafeEff $ \es0 -> do
37 size0 <- sizeEnv es0
37 size0 <- sizeEnv es0
38 istate <- R.createInternalState
38 istate <- R.createInternalState
39 mask $ \restore -> do
39 mask $ \restore -> do
40− es <- unsafeConsEnv (IdA (Resource istate)) noRelinker es0
40+ es <- unsafeConsEnv (DataA (Resource istate)) noRelinker es0
41 a <- restore (unEff m es) `catch` \e -> do
41 a <- restore (unEff m es) `catch` \e -> do
42 unsafeTailEnv size0 es
42 unsafeTailEnv size0 es
43 RI.stateCleanupChecked (Just e) istate
43 RI.stateCleanupChecked (Just e) istate
@@ -52,18 +52,18 @@ runResource m = unsafeEff $ \es0 -> do
52-- | Get the 'R.InternalState' of the current 'Resource' effect.
52-- | Get the 'R.InternalState' of the current 'Resource' effect.
53getInternalState :: Resource :> es => Eff es R.InternalState
53getInternalState :: Resource :> es => Eff es R.InternalState
54getInternalState = do
54getInternalState = do
55− IdA (Resource istate) <- getEffect
55+ DataA (Resource istate) <- getData
56 pure istate
56 pure istate
57
57
58-- | Run the 'Resource' effect with existing 'R.InternalState'.
58-- | Run the 'Resource' effect with existing 'R.InternalState'.
59--
59--
60-- /Note:/ the 'R.InternalState' will not be closed at the end.
60-- /Note:/ the 'R.InternalState' will not be closed at the end.
61runInternalState :: R.InternalState -> Eff (Resource : es) a -> Eff es a
61runInternalState :: R.InternalState -> Eff (Resource : es) a -> Eff es a
62−runInternalState istate = evalEffect $ IdA (Resource istate)
62+runInternalState istate = evalData (DataA (Resource istate))
63
63
64----------------------------------------
64----------------------------------------
65-- Orphan instance
65-- Orphan instance
66
66
67instance (IOE :> es, Resource :> es) => R.MonadResource (Eff es) where
67instance (IOE :> es, Resource :> es) => R.MonadResource (Eff es) where
68 liftResourceT (RI.ResourceT m) = unsafeEff $ \es -> do
68 liftResourceT (RI.ResourceT m) = unsafeEff $ \es -> do
69− getEnv es >>= \(IdA (Resource istate)) -> m istate
69+ getEnv es >>= \(DataA (Resource istate)) -> m istate
effectful/src/Effectful/Temporary.hs+1−1
@@ -19,7 +19,7 @@ data Temporary :: Effect where
19
19
20-- | Run the 'Temporary' effect.
20-- | Run the 'Temporary' effect.
21runTemporary :: IOE :> es => Eff (Temporary : es) a -> Eff es a
21runTemporary :: IOE :> es => Eff (Temporary : es) a -> Eff es a
22−runTemporary = evalEffect (IdA Temporary)
22+runTemporary = evalData (DataA Temporary)
23
23
24-- | Lifted 'T.withSystemTempFile'.
24-- | Lifted 'T.withSystemTempFile'.
25withSystemTempFile
25withSystemTempFile
effectful/src/Effectful/Timeout.hs+1−1
@@ -15,7 +15,7 @@ data Timeout :: Effect where
15
15
16-- | Run the 'Timeout' effect.
16-- | Run the 'Timeout' effect.
17runTimeout :: IOE :> es => Eff (Timeout : es) a -> Eff es a
17runTimeout :: IOE :> es => Eff (Timeout : es) a -> Eff es a
18−runTimeout = evalEffect (IdA Timeout)
18+runTimeout = evalData (DataA Timeout)
19
19
20-- | Lifted 'T.timeout'.
20-- | Lifted 'T.timeout'.
21timeout
21timeout