on master help sign in
Rename IdE to IdA and Handler to HandlerA
commit6c09a2f27f71c37f288c94e84f9b34848510b065 authorAndrzej Rybczak <andrzej@rybczak.net> dateSun 19 Dec 2021, 03:26 (5 years ago) parentdadd56f
18 files changed+62−62
effectful-core/src/Effectful/Dispatch/Dynamic.hs+2−2 effectful-core/src/Effectful/Dispatch/Static.hs+1−1 effectful-core/src/Effectful/Error.hs+3−3 effectful-core/src/Effectful/Internal/Effect.hs+3−3 effectful-core/src/Effectful/Internal/Monad.hs+14−14 effectful-core/src/Effectful/Reader.hs+3−3 effectful-core/src/Effectful/State/Local.hs+8−8 effectful-core/src/Effectful/State/Shared.hs+7−7 effectful-core/src/Effectful/Writer/Local.hs+5−5 effectful-core/src/Effectful/Writer/Shared.hs+5−5 effectful/src/Effectful/Concurrent/Effect.hs+1−1 effectful/src/Effectful/Environment.hs+1−1 effectful/src/Effectful/FileSystem.hs+1−1 effectful/src/Effectful/FileSystem/Effect.hs+1−1 effectful/src/Effectful/Process.hs+1−1 effectful/src/Effectful/Resource.hs+4−4 effectful/src/Effectful/Temporary.hs+1−1 effectful/src/Effectful/Timeout.hs+1−1
effectful-core/src/Effectful/Dispatch/Dynamic.hs+2−2
@@ -49,7 +49,7 @@ interpret
4949 -> Eff es a
5050interpret handler m = unsafeEff $ \es -> do
5151 les <- forkEnv es
52− (`unEff` es) $ runHandler (Handler les handler) m
52+ (`unEff` es) $ runHandlerA (HandlerA les handler) m
5353
5454-- | Interpret an effect using other effects.
5555reinterpret
@@ -62,7 +62,7 @@ reinterpret
6262reinterpret runHandlerEs handler m = unsafeEff $ \es -> do
6363 les0 <- forkEnv es
6464 (`unEff` les0) . runHandlerEs . unsafeEff $ \les -> do
65− (`unEff` es) $ runHandler (Handler les handler) m
65+ (`unEff` es) $ runHandlerA (HandlerA les handler) m
6666
6767----------------------------------------
6868-- Unlifts
effectful-core/src/Effectful/Dispatch/Static.hs+1−1
@@ -1,6 +1,6 @@
11module Effectful.Dispatch.Static
22 ( -- * Low level API
3− IdE(..)
3+ IdA(..)
44
55 -- ** Running
66 , runEffect
effectful-core/src/Effectful/Error.hs+3−3
@@ -72,7 +72,7 @@ runError
7272runError m = unsafeEff $ \es0 -> mask $ \release -> do
7373 eid <- newErrorId
7474 size0 <- sizeEnv es0
75− es <- unsafeConsEnv (IdE (Error @e eid)) noRelinker es0
75+ es <- unsafeConsEnv (IdA (Error @e eid)) noRelinker es0
7676 r <- tryErrorIO release eid es `onException` unsafeTailEnv size0 es
7777 unsafeTailEnv size0 es
7878 pure r
@@ -89,7 +89,7 @@ throwError
8989 -- ^ The error.
9090 -> Eff es a
9191throwError e = unsafeEff $ \es -> do
92− IdE (Error eid) <- getEnv @(Error e) es
92+ IdA (Error eid) <- getEnv @(Error e) es
9393 throwIO $ ErrorEx eid callStack e
9494
9595-- | Handle an error of type @e@.
@@ -101,7 +101,7 @@ catchError
101101 -- ^ A handler for errors in the inner computation.
102102 -> Eff es a
103103catchError m handler = unsafeEff $ \es -> do
104− IdE (Error eid) <- getEnv @(Error e) es
104+ IdA (Error eid) <- getEnv @(Error e) es
105105 size <- sizeEnv es
106106 catchErrorIO eid (unEff m es) $ \cs e -> do
107107 checkSizeEnv size es
effectful-core/src/Effectful/Internal/Effect.hs+3−3
@@ -8,7 +8,7 @@
88module Effectful.Internal.Effect
99 ( Effect
1010 , (:>)(..)
11− , IdE(..)
11+ , IdA(..)
1212
1313 -- * Utils
1414 , SuffixOf
@@ -24,8 +24,8 @@ import GHC.TypeLits
2424type Effect = (Type -> Type) -> Type -> Type
2525
2626-- | An adapter for statically dispatched effects.
27−newtype IdE :: Effect -> Type where
28− IdE :: (forall m r. e m r) -> IdE e
27+newtype IdA :: Effect -> Type where
28+ IdA :: (forall m r. e m r) -> IdA e
2929
3030-- | A constraint that requires that a particular effect @e@ is a member of the
3131-- type-level list @es@. This is used to parameterize an 'Effectful.Monad.Eff'
effectful-core/src/Effectful/Internal/Monad.hs+14−14
@@ -43,8 +43,8 @@ module Effectful.Internal.Monad
4343 -- ** Handler
4444 , EffectHandler
4545 , LocalEnv(..)
46− , Handler(..)
47− , runHandler
46+ , HandlerA(..)
47+ , runHandlerA
4848
4949 -- *** Sending operations
5050 , send
@@ -151,12 +151,12 @@ unsafeEff_ m = unsafeEff $ \_ -> m
151151-- | Get the current 'UnliftStrategy'.
152152unliftStrategy :: IOE :> es => Eff es UnliftStrategy
153153unliftStrategy = do
154− IdE (IOE unlift) <- getEffect
154+ IdA (IOE unlift) <- getEffect
155155 pure unlift
156156
157157-- | Locally override the 'UnliftStrategy' with the given value.
158158withUnliftStrategy :: IOE :> es => UnliftStrategy -> Eff es a -> Eff es a
159−withUnliftStrategy unlift = localEffect $ \_ -> IdE (IOE unlift)
159+withUnliftStrategy unlift = localEffect $ \_ -> IdA (IOE unlift)
160160
161161-- | Create an unlifting function with the current 'UnliftStrategy'.
162162--
@@ -272,7 +272,7 @@ newtype IOE :: Effect where
272272--
273273-- For running pure operations see 'runPureEff'.
274274runEff :: Eff '[IOE] a -> IO a
275−runEff m = unEff (evalEffect (IdE (IOE SeqUnlift)) m) =<< emptyEnv
275+runEff m = unEff (evalEffect (IdA (IOE SeqUnlift)) m) =<< emptyEnv
276276
277277instance IOE :> es => MonadIO (Eff es) where
278278 liftIO = unsafeEff_
@@ -302,7 +302,7 @@ data Prim :: Effect where
302302
303303-- | Run an 'Eff' operation with primitive state-transformer actions.
304304runPrim :: IOE :> es => Eff (Prim : es) a -> Eff es a
305−runPrim = evalEffect (IdE Prim)
305+runPrim = evalEffect (IdA Prim)
306306
307307instance Prim :> es => PrimMonad (Eff es) where
308308 type PrimState (Eff es) = RealWorld
@@ -334,26 +334,26 @@ type EffectHandler e es
334334-- | An adapter for dynamically dispatched effects.
335335--
336336-- Represents the effect handler bundled along with its environment.
337−data Handler :: Effect -> Type where
338− Handler :: !(Env es) -> !(EffectHandler e es) -> Handler e
337+data HandlerA :: Effect -> Type where
338+ HandlerA :: !(Env es) -> !(EffectHandler e es) -> HandlerA e
339339
340340-- | Run the effect with the given handler.
341−runHandler :: Handler e -> Eff (e : es) a -> Eff es a
342−runHandler e m = unsafeEff $ \es0 -> do
341+runHandlerA :: HandlerA e -> Eff (e : es) a -> Eff es a
342+runHandlerA e m = unsafeEff $ \es0 -> do
343343 size0 <- sizeEnv es0
344344 E.bracket (unsafeConsEnv e relinker es0)
345345 (unsafeTailEnv size0)
346346 (\es -> unEff m es)
347347 where
348− relinker :: Relinker Handler e
349− relinker = Relinker $ \relink (Handler handlerEs handle) -> do
348+ relinker :: Relinker HandlerA e
349+ relinker = Relinker $ \relink (HandlerA handlerEs handle) -> do
350350 newHandlerEs <- relink handlerEs
351− pure $ Handler newHandlerEs handle
351+ pure $ HandlerA newHandlerEs handle
352352
353353-- | Send an operation of the given effect to its handler for execution.
354354send :: (HasCallStack, e :> es) => e (Eff es) a -> Eff es a
355355send op = unsafeEff $ \es -> do
356− Handler handlerEs handle <- getEnv es
356+ HandlerA handlerEs handle <- getEnv es
357357 unEff (handle (LocalEnv es) op) handlerEs
358358
359359----------------------------------------
effectful-core/src/Effectful/Reader.hs+3−3
@@ -20,12 +20,12 @@ runReader
2020 :: r -- ^ An initial environment.
2121 -> Eff (Reader r : es) a
2222 -> Eff es a
23−runReader r = evalEffect (IdE (Reader r))
23+runReader r = evalEffect (IdA (Reader r))
2424
2525-- | Fetch the value of the environment.
2626ask :: Reader r :> es => Eff es r
2727ask = do
28− IdE (Reader r) <- getEffect
28+ IdA (Reader r) <- getEffect
2929 pure r
3030
3131-- | Retrieve a function of the current environment.
@@ -46,4 +46,4 @@ local
4646 => (r -> r) -- ^ The function to modify the environment.
4747 -> Eff es a
4848 -> Eff es a
49−local f = localEffect $ \(IdE (Reader r)) -> IdE (Reader (f r))
49+local f = localEffect $ \(IdA (Reader r)) -> IdA (Reader (f r))
effectful-core/src/Effectful/State/Local.hs+8−8
@@ -33,7 +33,7 @@ runState
3333 -> Eff (State s : es) a
3434 -> Eff es (a, s)
3535runState s0 m = do
36− (a, IdE (State s)) <- runEffect (IdE (State s0)) m
36+ (a, IdA (State s)) <- runEffect (IdA (State s0)) m
3737 pure (a, s)
3838
3939-- | Run a 'State' effect with the given initial state and return the final
@@ -42,7 +42,7 @@ evalState
4242 :: s -- ^ An initial state.
4343 -> Eff (State s : es) a
4444 -> Eff es a -- ^ A return value.
45−evalState s = evalEffect (IdE (State s))
45+evalState s = evalEffect (IdA (State s))
4646
4747-- | Run a 'State' effect with the given initial state and return the final
4848-- state, discarding the final value.
@@ -51,13 +51,13 @@ execState
5151 -> Eff (State s : es) a
5252 -> Eff es s
5353execState s0 m = do
54− IdE (State s) <- execEffect (IdE (State s0)) m
54+ IdA (State s) <- execEffect (IdA (State s0)) m
5555 pure s
5656
5757-- | Fetch the current value of the state.
5858get :: State s :> es => Eff es s
5959get = do
60− IdE (State s) <- getEffect
60+ IdA (State s) <- getEffect
6161 pure s
6262
6363-- | Get a function of the current state.
@@ -71,14 +71,14 @@ gets f = f <$> get
7171
7272-- | Set the current state to the given value.
7373put :: State s :> es => s -> Eff es ()
74−put s = putEffect (IdE (State s))
74+put s = putEffect (IdA (State s))
7575
7676-- | Apply the function to the current state and return a value.
7777state
7878 :: State s :> es
7979 => (s -> (a, s)) -- ^ The function to modify the state.
8080 -> Eff es a
81−state f = stateEffect $ \(IdE (State s0)) -> let (a, s) = f s0 in (a, IdE (State s))
81+state f = stateEffect $ \(IdA (State s0)) -> let (a, s) = f s0 in (a, IdA (State s))
8282
8383-- | Apply the function to the current state.
8484--
@@ -94,9 +94,9 @@ stateM
9494 :: State s :> es
9595 => (s -> Eff es (a, s)) -- ^ The function to modify the state.
9696 -> Eff es a
97−stateM f = stateEffectM $ \(IdE (State s0)) -> do
97+stateM f = stateEffectM $ \(IdA (State s0)) -> do
9898 (a, s) <- f s0
99− pure (a, IdE (State s))
99+ pure (a, IdA (State s))
100100
101101-- | Apply the monadic function to the current state.
102102--
effectful-core/src/Effectful/State/Shared.hs+7−7
@@ -33,7 +33,7 @@ newtype State s :: Effect where
3333runState :: s -> Eff (State s : es) a -> Eff es (a, s)
3434runState s m = do
3535 v <- unsafeEff_ $ newMVar s
36− a <- evalEffect (IdE (State v)) m
36+ a <- evalEffect (IdA (State v)) m
3737 (a, ) <$> unsafeEff_ (readMVar v)
3838
3939-- | Run a 'State' effect with the given initial state and return the final
@@ -41,20 +41,20 @@ runState s m = do
4141evalState :: s -> Eff (State s : es) a -> Eff es a
4242evalState s m = do
4343 v <- unsafeEff_ $ newMVar s
44− evalEffect (IdE (State v)) m
44+ evalEffect (IdA (State v)) m
4545
4646-- | Run a 'State' effect with the given initial state and return the final
4747-- state, discarding the final value.
4848execState :: s -> Eff (State s : es) a -> Eff es s
4949execState s m = do
5050 v <- unsafeEff_ $ newMVar s
51− _ <- evalEffect (IdE (State v)) m
51+ _ <- evalEffect (IdA (State v)) m
5252 unsafeEff_ $ readMVar v
5353
5454-- | Fetch the current value of the state.
5555get :: State s :> es => Eff es s
5656get = unsafeEff $ \es -> do
57− IdE (State v) <- getEnv es
57+ IdA (State v) <- getEnv es
5858 readMVar v
5959
6060-- | Get a function of the current state.
@@ -66,7 +66,7 @@ gets f = f <$> get
6666-- | Set the current state to the given value.
6767put :: State s :> es => s -> Eff es ()
6868put s = unsafeEff $ \es -> do
69− IdE (State v) <- getEnv es
69+ IdA (State v) <- getEnv es
7070 modifyMVar_ v $ \_ -> s `seq` pure s
7171
7272-- | Apply the function to the current state and return a value.
@@ -74,7 +74,7 @@ put s = unsafeEff $ \es -> do
7474-- /Note:/ this function gets an exclusive access to the state for its duration.
7575state :: State s :> es => (s -> (a, s)) -> Eff es a
7676state f = unsafeEff $ \es -> do
77− IdE (State v) <- getEnv es
77+ IdA (State v) <- getEnv es
7878 modifyMVar v $ \s0 -> let (a, s) = f s0 in s `seq` pure (s, a)
7979
8080-- | Apply the function to the current state.
@@ -90,7 +90,7 @@ modify f = state (\s -> ((), f s))
9090-- /Note:/ this function gets an exclusive access to the state for its duration.
9191stateM :: State s :> es => (s -> Eff es (a, s)) -> Eff es a
9292stateM f = unsafeEff $ \es -> do
93− IdE (State v) <- getEnv es
93+ IdA (State v) <- getEnv es
9494 modifyMVar v $ \s0 -> do
9595 (a, s) <- unEff (f s0) es
9696 s `seq` pure (s, a)
effectful-core/src/Effectful/Writer/Local.hs+5−5
@@ -38,19 +38,19 @@ newtype Writer w :: Effect where
3838-- output.
3939runWriter :: Monoid w => Eff (Writer w : es) a -> Eff es (a, w)
4040runWriter m = do
41− (a, IdE (Writer w)) <- runEffect (IdE (Writer mempty)) m
41+ (a, IdA (Writer w)) <- runEffect (IdA (Writer mempty)) m
4242 pure (a, w)
4343
4444-- | Run a 'Writer' effect and return the final output, discarding the final
4545-- value.
4646execWriter :: Monoid w => Eff (Writer w : es) a -> Eff es w
4747execWriter m = do
48− IdE (Writer w) <- execEffect (IdE (Writer mempty)) m
48+ IdA (Writer w) <- execEffect (IdA (Writer mempty)) m
4949 pure w
5050
5151-- | Append the given output to the overall output of the 'Writer'.
5252tell :: (Writer w :> es, Monoid w) => w -> Eff es ()
53−tell w = stateEffect $ \(IdE (Writer w0)) -> ((), IdE (Writer (w0 <> w)))
53+tell w = stateEffect $ \(IdA (Writer w0)) -> ((), IdA (Writer (w0 <> w)))
5454
5555-- | Execute an action and append its output to the overall output of the
5656-- 'Writer'.
@@ -60,13 +60,13 @@ tell w = stateEffect $ \(IdE (Writer w0)) -> ((), IdE (Writer (w0 <> w)))
6060-- the 'Writer'.
6161listen :: (Writer w :> es, Monoid w) => Eff es a -> Eff es (a, w)
6262listen m = unsafeEff $ \es -> mask $ \restore -> do
63− w0 <- stateEnv es $ \(IdE (Writer w)) -> (w, IdE (Writer mempty))
63+ w0 <- stateEnv es $ \(IdA (Writer w)) -> (w, IdA (Writer mempty))
6464 a <- restore (unEff m es) `onException` merge es w0
6565 (a, ) <$> merge es w0
6666 where
6767 merge es w0 =
6868 -- If an exception is thrown, restore w0 and keep parts of w1.
69− stateEnv es $ \(IdE (Writer w1)) -> (w1, IdE (Writer (w0 <> w1)))
69+ stateEnv es $ \(IdA (Writer w1)) -> (w1, IdA (Writer (w0 <> w1)))
7070
7171-- | Execute an action and append its output to the overall output of the
7272-- '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
3939runWriter :: Monoid w => Eff (Writer w : es) a -> Eff es (a, w)
4040runWriter m = do
4141 v <- unsafeEff_ $ newMVar mempty
42− a <- evalEffect (IdE (Writer v)) m
42+ a <- evalEffect (IdA (Writer v)) m
4343 (a, ) <$> unsafeEff_ (readMVar v)
4444
4545-- | Run a 'Writer' effect and return the final output, discarding the final
@@ -47,13 +47,13 @@ runWriter m = do
4747execWriter :: Monoid w => Eff (Writer w : es) a -> Eff es w
4848execWriter m = do
4949 v <- unsafeEff_ $ newMVar mempty
50− _ <- evalEffect (IdE (Writer v)) m
50+ _ <- evalEffect (IdA (Writer v)) m
5151 unsafeEff_ $ readMVar v
5252
5353-- | Append the given output to the overall output of the 'Writer'.
5454tell :: (Writer w :> es, Monoid w) => w -> Eff es ()
5555tell w1 = unsafeEff $ \es -> do
56− IdE (Writer v) <- getEnv es
56+ IdA (Writer v) <- getEnv es
5757 modifyMVar_ v $ \w0 -> let w = w0 <> w1 in w `seq` pure w
5858
5959-- | Execute an action and append its output to the overall output of the
@@ -70,14 +70,14 @@ listen m = unsafeEff $ \es -> do
7070 uninterruptibleMask $ \restore -> do
7171 v1 <- newMVar mempty
7272 -- Replace thread local MVar with a fresh one for isolated listening.
73− v0 <- stateEnv es $ \(IdE (Writer v)) -> (v, IdE (Writer v1))
73+ v0 <- stateEnv es $ \(IdA (Writer v)) -> (v, IdA (Writer v1))
7474 a <- restore (unEff m es) `onException` merge es v0 v1
7575 (a, ) <$> merge es v0 v1
7676 where
7777 -- Merge results accumulated in the local MVar with the mainline. If an
7878 -- exception was received while listening, merge results recorded so far.
7979 merge es v0 v1 = do
80− putEnv es $ IdE (Writer v0)
80+ putEnv es $ IdA (Writer v0)
8181 w1 <- readMVar v1
8282 modifyMVar_ v0 $ \w0 -> let w = w0 <> w1 in w `seq` pure w
8383 pure w1
effectful/src/Effectful/Concurrent/Effect.hs+1−1
@@ -17,4 +17,4 @@ data Concurrent :: Effect where
1717
1818-- | Run the 'Concurrent' effect.
1919runConcurrent :: IOE :> es => Eff (Concurrent : es) a -> Eff es a
20−runConcurrent = evalEffect (IdE Concurrent)
20+runConcurrent = evalEffect (IdA Concurrent)
effectful/src/Effectful/Environment.hs+1−1
@@ -29,7 +29,7 @@ data Environment :: Effect where
2929
3030-- | Run the 'Environment' effect.
3131runEnvironment :: IOE :> es => Eff (Environment : es) a -> Eff es a
32−runEnvironment = evalEffect (IdE Environment)
32+runEnvironment = evalEffect (IdA Environment)
3333
3434-- | Lifted 'E.getArgs'.
3535getArgs :: Environment :> es => Eff es [String]
effectful/src/Effectful/FileSystem.hs+1−1
@@ -101,7 +101,7 @@ data FileSystem :: Effect where
101101
102102-- | Run the 'FileSystem' effect.
103103runFileSystem :: IOE :> es => Eff (FileSystem : es) a -> Eff es a
104−runFileSystem = evalEffect (IdE FileSystem)
104+runFileSystem = evalEffect (IdA FileSystem)
105105
106106----------------------------------------
107107-- Actions on directories
effectful/src/Effectful/FileSystem/Effect.hs+1−1
@@ -12,4 +12,4 @@ data FileSystem :: Effect where
1212
1313-- | Run the 'FileSystem' effect.
1414runFileSystem :: IOE :> es => Eff (FileSystem : es) a -> Eff es a
15−runFileSystem = evalEffect (IdE FileSystem)
15+runFileSystem = evalEffect (IdA FileSystem)
effectful/src/Effectful/Process.hs+1−1
@@ -59,7 +59,7 @@ data Process :: Effect where
5959 Process :: Process m r
6060
6161runProcess :: IOE :> es => Eff (Process : es) a -> Eff es a
62−runProcess = evalEffect (IdE Process)
62+runProcess = evalEffect (IdA Process)
6363
6464----------------------------------------
6565-- Running sub-processes
effectful/src/Effectful/Resource.hs+4−4
@@ -37,7 +37,7 @@ runResource m = unsafeEff $ \es0 -> do
3737 size0 <- sizeEnv es0
3838 istate <- R.createInternalState
3939 mask $ \restore -> do
40− es <- unsafeConsEnv (IdE (Resource istate)) noRelinker es0
40+ es <- unsafeConsEnv (IdA (Resource istate)) noRelinker es0
4141 a <- restore (unEff m es) `catch` \e -> do
4242 unsafeTailEnv size0 es
4343 RI.stateCleanupChecked (Just e) istate
@@ -52,18 +52,18 @@ runResource m = unsafeEff $ \es0 -> do
5252-- | Get the 'R.InternalState' of the current 'Resource' effect.
5353getInternalState :: Resource :> es => Eff es R.InternalState
5454getInternalState = do
55− IdE (Resource istate) <- getEffect
55+ IdA (Resource istate) <- getEffect
5656 pure istate
5757
5858-- | Run the 'Resource' effect with existing 'R.InternalState'.
5959--
6060-- /Note:/ the 'R.InternalState' will not be closed at the end.
6161runInternalState :: R.InternalState -> Eff (Resource : es) a -> Eff es a
62−runInternalState istate = evalEffect $ IdE (Resource istate)
62+runInternalState istate = evalEffect $ IdA (Resource istate)
6363
6464----------------------------------------
6565-- Orphan instance
6666
6767instance (IOE :> es, Resource :> es) => R.MonadResource (Eff es) where
6868 liftResourceT (RI.ResourceT m) = unsafeEff $ \es -> do
69− getEnv es >>= \(IdE (Resource istate)) -> m istate
69+ getEnv es >>= \(IdA (Resource istate)) -> m istate
effectful/src/Effectful/Temporary.hs+1−1
@@ -19,7 +19,7 @@ data Temporary :: Effect where
1919
2020-- | Run the 'Temporary' effect.
2121runTemporary :: IOE :> es => Eff (Temporary : es) a -> Eff es a
22−runTemporary = evalEffect (IdE Temporary)
22+runTemporary = evalEffect (IdA Temporary)
2323
2424-- | Lifted 'T.withSystemTempFile'.
2525withSystemTempFile
effectful/src/Effectful/Timeout.hs+1−1
@@ -15,7 +15,7 @@ data Timeout :: Effect where
1515
1616-- | Run the 'Timeout' effect.
1717runTimeout :: IOE :> es => Eff (Timeout : es) a -> Eff es a
18−runTimeout = evalEffect (IdE Timeout)
18+runTimeout = evalEffect (IdA Timeout)
1919
2020-- | Lifted 'T.timeout'.
2121timeout