@@ -13,7 +13,7 @@ import Data.Tuple
1313-- | to the `Identity` monad.
1414type RWS r w s = RWST r w s Identity
1515
16- -- | Create an action in the `RWS` monad from a function which uses the
16+ -- | Create an action in the `RWS` monad from a function which uses the
1717-- | global context and state explicitly.
1818rws :: forall r w s a . (r -> s -> See s a w ) -> RWS r w s a
1919rws f = RWST \r s -> return $ f r s
@@ -37,59 +37,3 @@ mapRWS f = mapRWST (runIdentity >>> f >>> Identity)
3737-- | Change the type of the context in a `RWS` action
3838withRWS :: forall r1 r2 w s a . (r2 -> s -> Tuple r1 s ) -> RWS r1 w s a -> RWS r2 w s a
3939withRWS = withRWST
40-
41- -- | Get the context of a `RWS` action
42- ask :: forall r w s m . (Applicative m , Monoid w ) => RWST r w s m r
43- ask = RWST \r s -> pure $ mkSee s r mempty
44-
45- -- | Locally change the context of a `RWS` action.
46- local :: forall r w s m a . (r -> r ) -> RWST r w s m a -> RWST r w s m a
47- local f m = RWST \r s -> runRWST m (f r) s
48-
49- -- | Read a value which depends on the context in a `RWS` action.
50- reader :: forall r w s m a . (Applicative m , Monoid w ) => (r -> a ) -> RWST r w s m a
51- reader f = RWST \r s -> pure $ mkSee s (f r) mempty
52-
53- -- | Write to the accumulator in a `RWS` action
54- writer :: forall r w s m a . (Applicative m ) => Tuple a w -> RWST r w s m a
55- writer (Tuple a w) = RWST \_ s -> pure $ {state: s, result: a, log: w}
56-
57- -- | Execute a `RWS` action, and return the changes to the accumulator along with the return value
58- listen :: forall r w s m a . (Monad m ) => RWST r w s m a -> RWST r w s m (Tuple a w )
59- listen m = RWST \r s -> runRWST m r s >>= \{state = s', result = a, log = w} -> pure $ {state: s', result: Tuple a w, log: w}
60-
61- -- | Execute a `RWS` action and modify the accumulator
62- pass :: forall r w s m a . (Monad m ) => RWST r w s m (Tuple a (w -> w )) -> RWST r w s m a
63- pass m = RWST \r s -> runRWST m r s >>= \{result = Tuple a f, state = s', log = w} -> pure $ {state: s', result: a, log: f w}
64-
65- -- | Append a value to the accumulator in a `RWS` action
66- tell :: forall r w s m . (Applicative m ) => w -> RWST r w s m Unit
67- tell w = writer (Tuple unit w)
68-
69- -- | Execute a `RWS` action, and return a value which depends on the accumulator along with the return value
70- listens :: forall r w s m a b . (Monad m ) => (w -> b ) -> RWST r w s m a -> RWST r w s m (Tuple a b )
71- listens f m = RWST \r s -> runRWST m r s >>= \{state = s', result = a, log = w} -> pure $ {state: s', result: Tuple a (f w), log: w}
72-
73- -- | Modify the accumulator in a `RWS` action
74- censor :: forall r w s m a . (Monad m ) => (w -> w ) -> RWST r w s m a -> RWST r w s m a
75- censor f m = RWST \r s -> runRWST m r s >>= \see -> pure $ see{log = f see.log}
76-
77- -- | Get or modify the state in a `RWS` action
78- state :: forall r w s m a . (Applicative m , Monoid w ) => (s -> Tuple a s ) -> RWST r w s m a
79- state f = RWST \_ s -> case f s of Tuple a s' -> pure $ mkSee s' a mempty
80-
81- -- | Get the state in a `RWS` action
82- get :: forall r w s m . (Applicative m , Monoid w ) => RWST r w s m s
83- get = state \s -> Tuple s s
84-
85- -- | Get a value which depends on the state in a `RWS` action
86- gets :: forall r w s m a . (Applicative m , Monoid w ) => (s -> a ) -> RWST r w s m a
87- gets f = state \s -> Tuple (f s) s
88-
89- -- | Set the state in a `RWS` action
90- put :: forall r w s m . (Applicative m , Monoid w ) => s -> RWST r w s m Unit
91- put s = state \_ -> Tuple unit s
92-
93- -- | Modify the state in a `RWS` action
94- modify :: forall r w s m . (Applicative m , Monoid w ) => (s -> s ) -> RWST r w s m Unit
95- modify f = state \s -> Tuple unit (f s)
0 commit comments