on f749af5 help sign in
.github/workflows/haskell-ci.yml+5
since splitsnapshots
unifiedsplit
@@ -37,6 +37,11 @@ jobs:
37 compilerVersion: 9.2.1
37 compilerVersion: 9.2.1
38 setup-method: ghcup
38 setup-method: ghcup
39 allow-failure: false
39 allow-failure: false
40+ - compiler: ghc-9.0.1
41+ compilerKind: ghc
42+ compilerVersion: 9.0.1
43+ setup-method: hvr-ppa
44+ allow-failure: false
40 - compiler: ghc-8.10.7
45 - compiler: ghc-8.10.7
41 compilerKind: ghc
46 compilerKind: ghc
42 compilerVersion: 8.10.7
47 compilerVersion: 8.10.7
effectful-core/effectful-core.cabal+1−1
@@ -18,7 +18,7 @@ description: An easy to use, performant extensible effects library with seamless
18
18
19extra-source-files: CHANGELOG.md
19extra-source-files: CHANGELOG.md
20
20
21−tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.2.1
21+tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.0.1 || ==9.2.1
22
22
23bug-reports: https://github.com/arybczak/effectful/issues
23bug-reports: https://github.com/arybczak/effectful/issues
24source-repository head
24source-repository head
effectful-core/src/Effectful/Dispatch/Dynamic.hs+1−13
@@ -32,8 +32,7 @@ module Effectful.Dispatch.Dynamic
32 ) where
32 ) where
33
33
34import Control.Monad.IO.Unlift
34import Control.Monad.IO.Unlift
35−import Data.Kind
35+import GHC.Stack
36−import GHC.Stack (HasCallStack)
37
36
38import Effectful.Internal.Effect
37import Effectful.Internal.Effect
39import Effectful.Internal.Env
38import Effectful.Internal.Env
@@ -231,16 +230,5 @@ localLiftUnliftIO (LocalEnv les) strategy k = case strategy of
231 SeqUnlift -> liftIO $ seqUnliftIO les $ k unsafeEff_
230 SeqUnlift -> liftIO $ seqUnliftIO les $ k unsafeEff_
232 ConcUnlift p l -> liftIO $ concUnliftIO les p l $ k unsafeEff_
231 ConcUnlift p l -> liftIO $ concUnliftIO les p l $ k unsafeEff_
233
232
234−----------------------------------------
235−-- Utils
236−
237−-- | Require that the second list of effects is a suffix of the first one.
238−--
239−-- In other words, 'SuffixOf' @es@ @baseEs@ means "a suffix of @es@ is
240−-- @baseEs@".
241−type family SuffixOf (es :: [Effect]) (baseEs :: [Effect]) :: Constraint where
242− SuffixOf baseEs baseEs = ()
243− SuffixOf (e : es) baseEs = SuffixOf es baseEs
244−
245-- $setup
233-- $setup
246-- >>> import Control.Concurrent
234-- >>> import Control.Concurrent
effectful-core/src/Effectful/Dispatch/Static.hs+12−9
@@ -2,12 +2,12 @@ module Effectful.Dispatch.Static
2 ( -- * Low level API
2 ( -- * Low level API
3 DataA(..)
3 DataA(..)
4
4
5− -- ** Extending the environment
5+ -- ** Running
6 , runData
6 , runData
7 , evalData
7 , evalData
8 , execData
8 , execData
9
9
10− -- ** Data retrieval and update
10+ -- ** Modification
11 , getData
11 , getData
12 , putData
12 , putData
13 , stateData
13 , stateData
@@ -18,13 +18,6 @@ module Effectful.Dispatch.Static
18 , seqUnliftIO
18 , seqUnliftIO
19 , concUnliftIO
19 , concUnliftIO
20
20
21− -- ** Utils
22− , unEff
23− , unsafeEff
24− , unsafeEff_
25− , unsafeLiftMapIO
26− , unsafeUnliftIO
27−
28 -- * Primitive API
21 -- * Primitive API
29 , Env
22 , Env
30 , Relinker(..)
23 , Relinker(..)
@@ -46,8 +39,18 @@ module Effectful.Dispatch.Static
46 , putEnv
39 , putEnv
47 , stateEnv
40 , stateEnv
48 , modifyEnv
41 , modifyEnv
42+
43+ -- * Unsafe 'Eff' operations
44+ , unsafeEff
45+ , unsafeEff_
46+ , unsafeLiftMapIO
47+ , unsafeUnliftIO
48+
49+ -- * Utils
50+ , unEff
49 ) where
51 ) where
50
52
53+import Effectful.Internal.Effect
51import Effectful.Internal.Env
54import Effectful.Internal.Env
52import Effectful.Internal.Monad
55import Effectful.Internal.Monad
53
56
effectful-core/src/Effectful/Internal/Effect.hs+17−1
@@ -8,6 +8,10 @@
8module Effectful.Internal.Effect
8module Effectful.Internal.Effect
9 ( Effect
9 ( Effect
10 , (:>)(..)
10 , (:>)(..)
11+ , DataA(..)
12+
13+ -- * Utils
14+ , SuffixOf
11
15
12 -- * Re-exports
16 -- * Re-exports
13 , Type
17 , Type
@@ -19,6 +23,10 @@ import GHC.TypeLits
19-- | The kind of effects.
23-- | The kind of effects.
20type Effect = (Type -> Type) -> Type -> Type
24type Effect = (Type -> Type) -> Type -> Type
21
25
26+-- | An adapter for statically dispatched effects.
27+newtype DataA :: Effect -> Type where
28+ DataA :: (forall m r. e m r) -> DataA e
29+
22-- | 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
23-- 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'
24-- computation over an arbitrary list of effects, so long as @e@ is /somewhere/
32-- computation over an arbitrary list of effects, so long as @e@ is /somewhere/
@@ -28,7 +36,7 @@ type Effect = (Type -> Type) -> Type -> Type
28-- 'Integer' would likely use the following type:
36-- 'Integer' would likely use the following type:
29--
37--
30-- @
38-- @
31−-- 'Effectful.State.Local.State' 'Integer' ':>' es => 'Effectful.Monad.Eff' es ()
39+-- 'Effectful.State.State' 'Integer' ':>' es => 'Effectful.Monad.Eff' es ()
32-- @
40-- @
33class (e :: Effect) :> (es :: [Effect]) where
41class (e :: Effect) :> (es :: [Effect]) where
34 -- | Get the position of @e@ in @es@.
42 -- | Get the position of @e@ in @es@.
@@ -51,3 +59,11 @@ instance {-# OVERLAPPING #-} e :> (e : es) where
51
59
52instance e :> es => e :> (x : es) where
60instance e :> es => e :> (x : es) where
53 reifyIndex = 1 + reifyIndex @e @es
61 reifyIndex = 1 + reifyIndex @e @es
62+
63+-- | Require that the second list of effects is a suffix of the first one.
64+--
65+-- In other words, 'SuffixOf' @es@ @baseEs@ means "a suffix of @es@ is
66+-- @baseEs@".
67+type family SuffixOf (es :: [Effect]) (baseEs :: [Effect]) :: Constraint where
68+ SuffixOf baseEs baseEs = ()
69+ SuffixOf (e : es) baseEs = SuffixOf es baseEs
effectful-core/src/Effectful/Internal/Env.hs+20−25
@@ -1,4 +1,3 @@
1−{-# LANGUAGE MagicHash #-}
2{-# OPTIONS_HADDOCK not-home #-}
1{-# OPTIONS_HADDOCK not-home #-}
3-- | The environment for the 'Effectful.Internal.Monad.Eff' monad.
2-- | The environment for the 'Effectful.Internal.Monad.Eff' monad.
4--
3--
@@ -43,7 +42,7 @@ import Control.Monad
43import Control.Monad.Primitive
42import Control.Monad.Primitive
44import Data.IORef
43import Data.IORef
45import Data.Primitive.SmallArray
44import Data.Primitive.SmallArray
46−import GHC.Exts (Any, SmallMutableArray#)
45+import GHC.Exts (Any)
47import GHC.Stack (HasCallStack)
46import GHC.Stack (HasCallStack)
48import Unsafe.Coerce
47import Unsafe.Coerce
49import qualified Data.IntMap.Strict as IM
48import qualified Data.IntMap.Strict as IM
@@ -418,43 +417,43 @@ unsafeTailEnv len (Env fork gref _) = case fork of
418
417
419-- | Extract a specific data type from the environment.
418-- | Extract a specific data type from the environment.
420getEnv
419getEnv
421− :: forall e adapter es. e :> es
420+ :: forall e es adapter. e :> es
422 => Env es
421 => Env es
423 -> IO (adapter e)
422 -> IO (adapter e)
424getEnv env = do
423getEnv env = do
425− Location i es <- getLocation (reifyIndex @e @es) env
424+ (i, es) <- getLocation (reifyIndex @e @es) env
426 fromAny <$> readSmallArray es i
425 fromAny <$> readSmallArray es i
427
426
428-- | Replace the data type in the environment with a new value (in place).
427-- | Replace the data type in the environment with a new value (in place).
429putEnv
428putEnv
430− :: forall e adapter es. e :> es
429+ :: forall e es adapter. e :> es
431 => Env es
430 => Env es
432 -> adapter e
431 -> adapter e
433 -> IO ()
432 -> IO ()
434putEnv env e = do
433putEnv env e = do
435− Location i es <- getLocation (reifyIndex @e @es) env
434+ (i, es) <- getLocation (reifyIndex @e @es) env
436 e `seq` writeSmallArray es i (toAny e)
435 e `seq` writeSmallArray es i (toAny e)
437
436
438-- | Modify the data type in the environment (in place) and return a value.
437-- | Modify the data type in the environment (in place) and return a value.
439stateEnv
438stateEnv
440− :: forall e adapter es a. e :> es
439+ :: forall e es adapter a. e :> es
441 => Env es
440 => Env es
442 -> (adapter e -> (a, adapter e))
441 -> (adapter e -> (a, adapter e))
443 -> IO a
442 -> IO a
444stateEnv env f = do
443stateEnv env f = do
445− Location i es <- getLocation (reifyIndex @e @es) env
444+ (i, es) <- getLocation (reifyIndex @e @es) env
446 (a, e) <- f . fromAny <$> readSmallArray es i
445 (a, e) <- f . fromAny <$> readSmallArray es i
447 e `seq` writeSmallArray es i (toAny e)
446 e `seq` writeSmallArray es i (toAny e)
448 pure a
447 pure a
449
448
450-- | Modify the data type in the environment (in place).
449-- | Modify the data type in the environment (in place).
451modifyEnv
450modifyEnv
452− :: forall e adapter es. e :> es
451+ :: forall e es adapter. e :> es
453 => Env es
452 => Env es
454 -> (adapter e -> adapter e)
453 -> (adapter e -> adapter e)
455 -> IO ()
454 -> IO ()
456modifyEnv env f = do
455modifyEnv env f = do
457− Location i es <- getLocation (reifyIndex @e @es) env
456+ (i, es) <- getLocation (reifyIndex @e @es) env
458 e <- f . fromAny <$> readSmallArray es i
457 e <- f . fromAny <$> readSmallArray es i
459 e `seq` writeSmallArray es i (toAny e)
458 e `seq` writeSmallArray es i (toAny e)
460
459
@@ -470,17 +469,13 @@ emptyEnvRef = do
470 fs <- newSmallArray 0 undefinedData
469 fs <- newSmallArray 0 undefinedData
471 newIORef $ EnvRef 0 es fs
470 newIORef $ EnvRef 0 es fs
472
471
473−-- | Location with unboxed fields to make GHC generate Core without unnecessary
474−-- reboxing around the local 'go' function from 'getLocation'.
475−data Location = Location !Int !(SmallMutableArray RealWorld Any)
476−
477-- | Determine location of the data type in the environment.
472-- | Determine location of the data type in the environment.
478getLocation
473getLocation
479 :: Int
474 :: Int
480 -> Env es
475 -> Env es
481− -> IO Location
476+ -> IO (Int, SmallMutableArray RealWorld Any)
482getLocation ixE (Env fork ref _) = do
477getLocation ixE (Env fork ref _) = do
483− EnvRef n es@(SmallMutableArray es#) _ <- readIORef ref
478+ EnvRef n es _ <- readIORef ref
484 -- Optimized for the common access pattern:
479 -- Optimized for the common access pattern:
485 --
480 --
486 -- - Most application code has no access to forks, in which case we look at
481 -- - Most application code has no access to forks, in which case we look at
@@ -489,25 +484,25 @@ getLocation ixE (Env fork ref _) = do
489 -- - Effect handlers will most likely access the newest fork with handler
484 -- - Effect handlers will most likely access the newest fork with handler
490 -- specific effects for reinterpretation.
485 -- specific effects for reinterpretation.
491 case fork of
486 case fork of
492− NoFork -> pure $ Location (ix n) es
487+ NoFork -> pure (ix n, es)
493 Forks _ baseIx lref forks -> do
488 Forks _ baseIx lref forks -> do
494 EnvRef ln les _ <- readIORef lref
489 EnvRef ln les _ <- readIORef lref
495 let i = ix (baseIx + ln)
490 let i = ix (baseIx + ln)
496 if i >= baseIx
491 if i >= baseIx
497− then pure $ Location (i - baseIx) les
492+ then pure (i - baseIx, les)
498− else go es# i forks
493+ else go es i forks
499 where
494 where
500− go :: SmallMutableArray# RealWorld Any
495+ go :: SmallMutableArray RealWorld Any
501 -> Int
496 -> Int
502 -> Forks
497 -> Forks
503− -> IO Location
498+ -> IO (Int, SmallMutableArray RealWorld Any)
504− go es# i = \case
499+ go es i = \case
505− NoFork -> pure $ Location i (SmallMutableArray es#)
500+ NoFork -> pure (i, es)
506 Forks _ baseIx lref forks -> do
501 Forks _ baseIx lref forks -> do
507 EnvRef _ les _ <- readIORef lref
502 EnvRef _ les _ <- readIORef lref
508 if i >= baseIx
503 if i >= baseIx
509− then pure $ Location (i - baseIx) les
504+ then pure (i - baseIx, les)
510− else go es# i forks
505+ else go es i forks
511
506
512 ix :: Int -> Int
507 ix :: Int -> Int
513 ix n = n - ixE - 1
508 ix n = n - ixE - 1
effectful-core/src/Effectful/Internal/Monad.hs+25−38
@@ -6,7 +6,7 @@
6-- This module is intended for internal use only, and may change without warning
6-- This module is intended for internal use only, and may change without warning
7-- in subsequent releases.
7-- in subsequent releases.
8module Effectful.Internal.Monad
8module Effectful.Internal.Monad
9− ( -- * The 'Eff' monad
9+ ( -- * Monad
10 Eff
10 Eff
11 , runPureEff
11 , runPureEff
12
12
@@ -22,11 +22,11 @@ module Effectful.Internal.Monad
22 , IOE
22 , IOE
23 , runEff
23 , runEff
24
24
25− -- * Prim
25+ -- * Primitive
26 , Prim
26 , Prim
27 , runPrim
27 , runPrim
28
28
29− -- * Unlift strategies
29+ -- ** Unlift strategies
30 , UnliftStrategy(..)
30 , UnliftStrategy(..)
31 , Persistence(..)
31 , Persistence(..)
32 , Limit(..)
32 , Limit(..)
@@ -34,24 +34,29 @@ module Effectful.Internal.Monad
34 , withUnliftStrategy
34 , withUnliftStrategy
35 , withEffToIO
35 , withEffToIO
36
36
37− -- ** Low-level unlifts
37+ --- *** Low-level helpers
38 , seqUnliftIO
38 , seqUnliftIO
39 , concUnliftIO
39 , concUnliftIO
40
40
41 -- * Effects
41 -- * Effects
42
42
43− -- ** Dynamic dispatch
43+ -- ** Handler
44 , EffectHandler
44 , EffectHandler
45 , LocalEnv(..)
45 , LocalEnv(..)
46 , HandlerA(..)
46 , HandlerA(..)
47 , runHandler
47 , runHandler
48+
49+ -- *** Sending operations
48 , send
50 , send
49
51
50− -- ** Static dispatch
52+ -- ** Primitive
51− , DataA(..)
53+
54+ -- *** Running
52 , runData
55 , runData
53 , evalData
56 , evalData
54 , execData
57 , execData
58+
59+ -- *** Modification
55 , getData
60 , getData
56 , putData
61 , putData
57 , stateData
62 , stateData
@@ -87,16 +92,17 @@ type role Eff nominal representational
87-- would have the following type:
92-- would have the following type:
88--
93--
89-- @
94-- @
90−-- 'Eff' '['Effectful.Reader.Reader' 'String', 'Effectful.State.Local.State' 'Bool'] 'Integer'
95+-- 'Eff' '['Effectful.Reader.Reader' 'String', 'Effectful.State.State' 'Bool'] 'Integer'
91-- @
96-- @
92--
97--
93-- Normally, a concrete list of effects is not used to parameterize 'Eff'.
98-- Normally, a concrete list of effects is not used to parameterize 'Eff'.
94-- Instead, the '(:>)' type class is used to express constraints on the list of
99-- Instead, the '(:>)' type class is used to express constraints on the list of
95-- effects without coupling a computation to a concrete list of effects. For
100-- effects without coupling a computation to a concrete list of effects. For
96−-- example, the above example would be expressed with the following type:
101+-- example, the above example would more commonly be expressed with the
102+-- following type:
97--
103--
98-- @
104-- @
99−-- ('Effectful.Reader.Reader' 'String' ':>' es, 'Effectful.State.Local.State' 'Bool' ':>' es) => 'Eff' es 'Integer'
105+-- ('Effectful.Reader.Reader' 'String' ':>' es, 'Effectful.State.State' 'Bool' ':>' es) => 'Eff' es 'Integer'
100-- @
106-- @
101--
107--
102-- This abstraction allows the computation to be used in functions that may
108-- This abstraction allows the computation to be used in functions that may
@@ -110,12 +116,12 @@ newtype Eff (es :: [Effect]) a = Eff (Env es -> IO a)
110-- For running computations with side effects see 'runEff'.
116-- For running computations with side effects see 'runEff'.
111runPureEff :: Eff '[] a -> a
117runPureEff :: Eff '[] a -> a
112runPureEff (Eff m) =
118runPureEff (Eff m) =
113− -- unsafeDupablePerformIO is safe here since IOE was not on the stack, so no
119+ -- unsafePerformIO is safe here since IOE was not on the stack, so no IO with
114− -- IO with side effects was performed (unless someone sneakily introduced side
120+ -- side effects was performed (unless someone sneakily introduced side effects
115− -- effects with unsafeEff, but then all bets are off).
121+ -- with unsafeEff, but then all bets are off).
116 --
122 --
117 -- Moreover, internals don't allocate any resources that require explicit
123 -- Moreover, internals don't allocate any resources that require explicit
118− -- cleanup actions to run.
124+ -- cleanup actions to run, so the "Dupable" part should also be just fine.
119 unsafeDupablePerformIO $ m =<< emptyEnv
125 unsafeDupablePerformIO $ m =<< emptyEnv
120
126
121----------------------------------------
127----------------------------------------
@@ -158,7 +164,7 @@ withUnliftStrategy unlift = localData $ \_ -> DataA (IOE unlift)
158-- constraint for accurate stack traces in case an insufficiently powerful
164-- constraint for accurate stack traces in case an insufficiently powerful
159-- 'UnliftStrategy' is used and the unlifting function fails.
165-- 'UnliftStrategy' is used and the unlifting function fails.
160--
166--
161−-- /Note:/ the strategy is reset to 'SeqUnlift' inside the continuation.
167+-- /Note:/ the strategy is reset to 'SeqUnlift' for new threads.
162withEffToIO
168withEffToIO
163 :: (HasCallStack, IOE :> es)
169 :: (HasCallStack, IOE :> es)
164 => ((forall r. Eff es r -> IO r) -> IO a)
170 => ((forall r. Eff es r -> IO r) -> IO a)
@@ -303,7 +309,7 @@ instance Prim :> es => PrimMonad (Eff es) where
303 primitive = unsafeEff_ . IO
309 primitive = unsafeEff_ . IO
304
310
305----------------------------------------
311----------------------------------------
306−-- Dynamic dispatch
312+-- Handler
307
313
308type role LocalEnv nominal nominal
314type role LocalEnv nominal nominal
309
315
@@ -327,11 +333,11 @@ type EffectHandler e es
327
333
328-- | An adapter for dynamically dispatched effects.
334-- | An adapter for dynamically dispatched effects.
329--
335--
330−-- Represents the effect handler bundled with its environment.
336+-- Represents the effect handler bundled along with its environment.
331data HandlerA :: Effect -> Type where
337data HandlerA :: Effect -> Type where
332 HandlerA :: !(Env es) -> !(EffectHandler e es) -> HandlerA e
338 HandlerA :: !(Env es) -> !(EffectHandler e es) -> HandlerA e
333
339
334−-- | Run a dynamically dispatched effect with the given handler.
340+-- | Run the effect with the given handler.
335runHandler :: HandlerA e -> Eff (e : es) a -> Eff es a
341runHandler :: HandlerA e -> Eff (e : es) a -> Eff es a
336runHandler e m = unsafeEff $ \es0 -> do
342runHandler e m = unsafeEff $ \es0 -> do
337 size0 <- sizeEnv es0
343 size0 <- sizeEnv es0
@@ -351,17 +357,8 @@ send op = unsafeEff $ \es -> do
351 unEff (handle (LocalEnv es) op) handlerEs
357 unEff (handle (LocalEnv es) op) handlerEs
352
358
353----------------------------------------
359----------------------------------------
354−-- Static dispatch
360+-- Helpers
355−
356−-- | An adapter for statically dispatched effects.
357−--
358−-- Represents an arbitrary data type with the appropriate number of phantom type
359−-- parameters.
360−newtype DataA :: Effect -> Type where
361− DataA :: (forall m r. e m r) -> DataA e
362
361
363−-- | Run a statically dispatched effect with the given initial state and return
364−-- the final value along with the final state.
365runData :: DataA e -> Eff (e : es) a -> Eff es (a, DataA e)
362runData :: DataA e -> Eff (e : es) a -> Eff es (a, DataA e)
366runData e0 m = unsafeEff $ \es0 -> do
363runData e0 m = unsafeEff $ \es0 -> do
367 size0 <- sizeEnv es0
364 size0 <- sizeEnv es0
@@ -369,8 +366,6 @@ runData e0 m = unsafeEff $ \es0 -> do
369 (unsafeTailEnv size0)
366 (unsafeTailEnv size0)
370 (\es -> (,) <$> unEff m es <*> getEnv es)
367 (\es -> (,) <$> unEff m es <*> getEnv es)
371
368
372−-- | Run a statically dispatched effect with the given initial state and return
373−-- the final value, discarding the final state.
374evalData :: DataA e -> Eff (e : es) a -> Eff es a
369evalData :: DataA e -> Eff (e : es) a -> Eff es a
375evalData e m = unsafeEff $ \es0 -> do
370evalData e m = unsafeEff $ \es0 -> do
376 size0 <- sizeEnv es0
371 size0 <- sizeEnv es0
@@ -378,8 +373,6 @@ evalData e m = unsafeEff $ \es0 -> do
378 (unsafeTailEnv size0)
373 (unsafeTailEnv size0)
379 (\es -> unEff m es)
374 (\es -> unEff m es)
380
375
381−-- | Run a statically dispatched effect with the given initial state and return
382−-- the final state, discarding the final value.
383execData :: DataA e -> Eff (e : es) a -> Eff es (DataA e)
376execData :: DataA e -> Eff (e : es) a -> Eff es (DataA e)
384execData e0 m = unsafeEff $ \es0 -> do
377execData e0 m = unsafeEff $ \es0 -> do
385 size0 <- sizeEnv es0
378 size0 <- sizeEnv es0
@@ -387,27 +380,21 @@ execData e0 m = unsafeEff $ \es0 -> do
387 (unsafeTailEnv size0)
380 (unsafeTailEnv size0)
388 (\es -> unEff m es *> getEnv es)
381 (\es -> unEff m es *> getEnv es)
389
382
390−-- | Fetch the current state of the effect.
391getData :: e :> es => Eff es (DataA e)
383getData :: e :> es => Eff es (DataA e)
392getData = unsafeEff $ \es -> getEnv es
384getData = unsafeEff $ \es -> getEnv es
393
385
394−-- | Set the current state of the effect to the given value.
395putData :: e :> es => DataA e -> Eff es ()
386putData :: e :> es => DataA e -> Eff es ()
396putData e = unsafeEff $ \es -> putEnv es e
387putData e = unsafeEff $ \es -> putEnv es e
397
388
398−-- | Apply the function to the current state of the effect and return a value.
399stateData :: e :> es => (DataA e -> (a, DataA e)) -> Eff es a
389stateData :: e :> es => (DataA e -> (a, DataA e)) -> Eff es a
400stateData f = unsafeEff $ \es -> stateEnv es f
390stateData f = unsafeEff $ \es -> stateEnv es f
401
391
402−-- | Apply the monadic function to the current state of the effect and return a
403−-- value.
404stateDataM :: e :> es => (DataA e -> Eff es (a, DataA e)) -> Eff es a
392stateDataM :: e :> es => (DataA e -> Eff es (a, DataA e)) -> Eff es a
405stateDataM f = unsafeEff $ \es -> E.mask $ \release -> do
393stateDataM f = unsafeEff $ \es -> E.mask $ \release -> do
406 (a, e) <- (\e -> release $ unEff (f e) es) =<< getEnv es
394 (a, e) <- (\e -> release $ unEff (f e) es) =<< getEnv es
407 putEnv es e
395 putEnv es e
408 pure a
396 pure a
409
397
410−-- | Execute a computation with a temporarily modified state of the effect.
411localData :: e :> es => (DataA e -> DataA e) -> Eff es a -> Eff es a
398localData :: e :> es => (DataA e -> DataA e) -> Eff es a -> Eff es a
412localData f m = unsafeEff $ \es -> do
399localData f m = unsafeEff $ \es -> do
413 E.bracket (stateEnv es $ \e -> (e, f e))
400 E.bracket (stateEnv es $ \e -> (e, f e))
effectful-core/src/Effectful/Writer/Local.hs+3−3
@@ -55,9 +55,9 @@ tell w = stateData $ \(DataA (Writer w0)) -> ((), DataA (Writer (w0 <> w)))
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'.
57--
57--
58−-- /Note:/ if an exception is received while the action is executed, the partial
58+-- /Note:/ if a runtime exception is received while the action is executed, the
59−-- output of the action will still be appended to the overall output of the
59+-- partial output of the action will still be appended to the overall output of
60−-- 'Writer':
60+-- the 'Writer':
61--
61--
62-- >>> :{
62-- >>> :{
63-- runEff . execWriter @String $ do
63-- runEff . execWriter @String $ do
effectful-core/src/Effectful/Writer/Shared.hs+3−3
@@ -59,9 +59,9 @@ tell w1 = unsafeEff $ \es -> do
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
60-- 'Writer'.
60-- 'Writer'.
61--
61--
62−-- /Note:/ if an exception is received while the action is executed, the partial
62+-- /Note:/ if a runtime exception is received while the action is executed, the
63−-- output of the action will still be appended to the overall output of the
63+-- partial output of the action will still be appended to the overall output of
64−-- 'Writer':
64+-- the 'Writer':
65--
65--
66-- >>> :{
66-- >>> :{
67-- runEff . execWriter @String $ do
67-- runEff . execWriter @String $ do
effectful/bench/Main.hs+3−3
@@ -97,11 +97,11 @@ filesize n = bgroup (show n)
97#ifdef VERSION_eff
97#ifdef VERSION_eff
98 , bench "eff" $ nfAppIO eff_calculateFileSizesDeep (take n files)
98 , bench "eff" $ nfAppIO eff_calculateFileSizesDeep (take n files)
99#endif
99#endif
100−#ifdef VERSION_mtl
101− , bench "mtl" $ nfAppIO mtl_calculateFileSizesDeep (take n files)
102−#endif
103#ifdef VERSION_polysemy
100#ifdef VERSION_polysemy
104 , bench "polysemy" $ nfAppIO poly_calculateFileSizesDeep (take n files)
101 , bench "polysemy" $ nfAppIO poly_calculateFileSizesDeep (take n files)
102+#endif
103+#ifdef VERSION_mtl
104+ , bench "mtl" $ nfAppIO mtl_calculateFileSizesDeep (take n files)
105#endif
105#endif
106 ]
106 ]
107 ]
107 ]
effectful/effectful.cabal+1−1
@@ -20,7 +20,7 @@ description: An easy to use, performant extensible effects library with seamless
20
20
21extra-source-files: CHANGELOG.md
21extra-source-files: CHANGELOG.md
22
22
23−tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.2.1
23+tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.0.1 || ==9.2.1
24
24
25bug-reports: https://github.com/arybczak/effectful/issues
25bug-reports: https://github.com/arybczak/effectful/issues
26source-repository head
26source-repository head