@@ -33,7 +33,7 @@ newtype State s :: Effect where
33runState :: s -> Eff (State s : es) a -> Eff es (a, s)
33runState :: s -> Eff (State s : es) a -> Eff es (a, s)
34runState s m = do
34runState s m = do
35 v <- unsafeEff_ $ newMVar s
35 v <- unsafeEff_ $ newMVar s
36− a <- evalEffect (IdE (State v)) m
36+ a <- evalEffect (IdA (State v)) m
37 (a, ) <$> unsafeEff_ (readMVar v)
37 (a, ) <$> unsafeEff_ (readMVar v)
39-- | Run a 'State' effect with the given initial state and return the final
39-- | Run a 'State' effect with the given initial state and return the final
@@ -41,20 +41,20 @@ runState s m = do
41evalState :: s -> Eff (State s : es) a -> Eff es a
41evalState :: s -> Eff (State s : es) a -> Eff es a
42evalState s m = do
42evalState s m = do
43 v <- unsafeEff_ $ newMVar s
43 v <- unsafeEff_ $ newMVar s
44− evalEffect (IdE (State v)) m
44+ evalEffect (IdA (State v)) m
46-- | Run a 'State' effect with the given initial state and return the final
46-- | Run a 'State' effect with the given initial state and return the final
47-- state, discarding the final value.
47-- state, discarding the final value.
48execState :: s -> Eff (State s : es) a -> Eff es s
48execState :: s -> Eff (State s : es) a -> Eff es s
49execState s m = do
49execState s m = do
50 v <- unsafeEff_ $ newMVar s
50 v <- unsafeEff_ $ newMVar s
51− _ <- evalEffect (IdE (State v)) m
51+ _ <- evalEffect (IdA (State v)) m
52 unsafeEff_ $ readMVar v
52 unsafeEff_ $ readMVar v
54-- | Fetch the current value of the state.
54-- | Fetch the current value of the state.
55get :: State s :> es => Eff es s
55get :: State s :> es => Eff es s
56get = unsafeEff $ \es -> do
56get = unsafeEff $ \es -> do
57− IdE (State v) <- getEnv es
57+ IdA (State v) <- getEnv es
58 readMVar v
58 readMVar v
60-- | Get a function of the current state.
60-- | Get a function of the current state.
@@ -66,7 +66,7 @@ gets f = f <$> get
66-- | Set the current state to the given value.
66-- | Set the current state to the given value.
67put :: State s :> es => s -> Eff es ()
67put :: State s :> es => s -> Eff es ()
68put s = unsafeEff $ \es -> do
68put s = unsafeEff $ \es -> do
69− IdE (State v) <- getEnv es
69+ IdA (State v) <- getEnv es
70 modifyMVar_ v $ \_ -> s `seq` pure s
70 modifyMVar_ v $ \_ -> s `seq` pure s
72-- | Apply the function to the current state and return a value.
72-- | Apply the function to the current state and return a value.
@@ -74,7 +74,7 @@ put s = unsafeEff $ \es -> do
74-- /Note:/ this function gets an exclusive access to the state for its duration.
74-- /Note:/ this function gets an exclusive access to the state for its duration.
75state :: State s :> es => (s -> (a, s)) -> Eff es a
75state :: State s :> es => (s -> (a, s)) -> Eff es a
76state f = unsafeEff $ \es -> do
76state f = unsafeEff $ \es -> do
77− IdE (State v) <- getEnv es
77+ IdA (State v) <- getEnv es
78 modifyMVar v $ \s0 -> let (a, s) = f s0 in s `seq` pure (s, a)
78 modifyMVar v $ \s0 -> let (a, s) = f s0 in s `seq` pure (s, a)
80-- | Apply the function to the current state.
80-- | Apply the function to the current state.
@@ -90,7 +90,7 @@ modify f = state (\s -> ((), f s))
90-- /Note:/ this function gets an exclusive access to the state for its duration.
90-- /Note:/ this function gets an exclusive access to the state for its duration.
91stateM :: State s :> es => (s -> Eff es (a, s)) -> Eff es a
91stateM :: State s :> es => (s -> Eff es (a, s)) -> Eff es a
92stateM f = unsafeEff $ \es -> do
92stateM f = unsafeEff $ \es -> do
93− IdE (State v) <- getEnv es
93+ IdA (State v) <- getEnv es
94 modifyMVar v $ \s0 -> do
94 modifyMVar v $ \s0 -> do
95 (a, s) <- unEff (f s0) es
95 (a, s) <- unEff (f s0) es
96 s `seq` pure (s, a)
96 s `seq` pure (s, a)