on master help sign in
A bit more efficient runState/execState
1e8a873Andrzej Rybczak
effectful.cabal+1−1
@@ -23,7 +23,7 @@ source-repository head
23 location: https://github.com/arybczak/effectful.git
23 location: https://github.com/arybczak/effectful.git
24
24
25flag benchmark-foreign-libraries
25flag benchmark-foreign-libraries
26− description: Include other effect libraries in the benchmarks
26+ description: Include other effect libraries in the benchmarks.
27 default: False
27 default: False
28
28
29common language
29common language
src/Effectful/State/MVar.hs+4−2
@@ -32,7 +32,8 @@ newtype State s :: Effect where
32runState :: s -> Eff (State s : es) a -> Eff es (a, s)
32runState :: s -> Eff (State s : es) a -> Eff es (a, s)
33runState s m = do
33runState s m = do
34 v <- unsafeEff_ $ newMVar s
34 v <- unsafeEff_ $ newMVar s
35− evalEffect (IdE (State v)) $ (,) <$> m <*> get
35+ a <- evalEffect (IdE (State v)) m
36+ (a, ) <$> unsafeEff_ (readMVar v)
36
37
37evalState :: s -> Eff (State s : es) a -> Eff es a
38evalState :: s -> Eff (State s : es) a -> Eff es a
38evalState s m = do
39evalState s m = do
@@ -42,7 +43,8 @@ evalState s m = do
42execState :: s -> Eff (State s : es) a -> Eff es s
43execState :: s -> Eff (State s : es) a -> Eff es s
43execState s m = do
44execState s m = do
44 v <- unsafeEff_ $ newMVar s
45 v <- unsafeEff_ $ newMVar s
45− evalEffect (IdE (State v)) $ m *> get
46+ _ <- evalEffect (IdE (State v)) m
47+ unsafeEff_ $ readMVar v
46
48
47get :: State s :> es => Eff es s
49get :: State s :> es => Eff es s
48get = do
50get = do