Skip to content

Commit 4aef7bd

Browse files
committed
Renaming See to RWSResult
1 parent 4541afc commit 4aef7bd

File tree

4 files changed

+38
-37
lines changed

4 files changed

+38
-37
lines changed

docs/Control/Monad/RWS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ to the `Identity` monad.
1414
#### `rws`
1515

1616
``` purescript
17-
rws :: forall r w s a. (r -> s -> See s a w) -> RWS r w s a
17+
rws :: forall r w s a. (r -> s -> RWSResult s a w) -> RWS r w s a
1818
```
1919

2020
Create an action in the `RWS` monad from a function which uses the
@@ -23,7 +23,7 @@ global context and state explicitly.
2323
#### `runRWS`
2424

2525
``` purescript
26-
runRWS :: forall r w s a. RWS r w s a -> r -> s -> See s a w
26+
runRWS :: forall r w s a. RWS r w s a -> r -> s -> RWSResult s a w
2727
```
2828

2929
Run a computation in the `RWS` monad.
@@ -47,7 +47,7 @@ Run a computation in the `RWS` monad, discarding the result
4747
#### `mapRWS`
4848

4949
``` purescript
50-
mapRWS :: forall r w1 w2 s a1 a2. (See s a1 w1 -> See s a2 w2) -> RWS r w1 s a1 -> RWS r w2 s a2
50+
mapRWS :: forall r w1 w2 s a1 a2. (RWSResult s a1 w1 -> RWSResult s a2 w2) -> RWS r w1 s a1 -> RWS r w2 s a2
5151
```
5252

5353
Change the types of the result and accumulator in a `RWS` action

docs/Control/Monad/RWS/Trans.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
This module defines the reader-writer-state monad transformer, `RWST`.
44

5-
#### `See`
5+
#### `RWSResult`
66

77
``` purescript
8-
data See state result writer
8+
data RWSResult state result writer
9+
= RWSResult state result writer
910
```
1011

1112
#### `RWST`
1213

1314
``` purescript
1415
newtype RWST r w s m a
15-
= RWST (r -> s -> m (See s a w))
16+
= RWST (r -> s -> m (RWSResult s a w))
1617
```
1718

1819
The reader-writer-state monad transformer, which combines the operations
@@ -38,7 +39,7 @@ instance monadRecRWST :: (Monoid w, MonadRec m) => MonadRec (RWST r w s m)
3839
#### `runRWST`
3940

4041
``` purescript
41-
runRWST :: forall r w s m a. RWST r w s m a -> r -> s -> m (See s a w)
42+
runRWST :: forall r w s m a. RWST r w s m a -> r -> s -> m (RWSResult s a w)
4243
```
4344

4445
Run a computation in the `RWST` monad.
@@ -62,7 +63,7 @@ Run a computation in the `RWST` monad, discarding the result.
6263
#### `mapRWST`
6364

6465
``` purescript
65-
mapRWST :: forall r w1 w2 s m1 m2 a1 a2. (m1 (See s a1 w1) -> m2 (See s a2 w2)) -> RWST r w1 s m1 a1 -> RWST r w2 s m2 a2
66+
mapRWST :: forall r w1 w2 s m1 m2 a1 a2. (m1 (RWSResult s a1 w1) -> m2 (RWSResult s a2 w2)) -> RWST r w1 s m1 a1 -> RWST r w2 s m2 a2
6667
```
6768

6869
Change the result and accumulator types in a `RWST` monad action.

src/Control/Monad/RWS.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ type RWS r w s = RWST r w s Identity
2626

2727
-- | Create an action in the `RWS` monad from a function which uses the
2828
-- | global context and state explicitly.
29-
rws :: forall r w s a. (r -> s -> See s a w) -> RWS r w s a
29+
rws :: forall r w s a. (r -> s -> RWSResult s a w) -> RWS r w s a
3030
rws f = RWST \r s -> return $ f r s
3131

3232
-- | Run a computation in the `RWS` monad.
33-
runRWS :: forall r w s a. RWS r w s a -> r -> s -> See s a w
33+
runRWS :: forall r w s a. RWS r w s a -> r -> s -> RWSResult s a w
3434
runRWS m r s = runIdentity $ runRWST m r s
3535

3636
-- | Run a computation in the `RWS` monad, discarding the final state
@@ -42,7 +42,7 @@ execRWS :: forall r w s a. RWS r w s a -> r -> s -> Tuple s w
4242
execRWS m r s = runIdentity $ execRWST m r s
4343

4444
-- | Change the types of the result and accumulator in a `RWS` action
45-
mapRWS :: forall r w1 w2 s a1 a2. (See s a1 w1 -> See s a2 w2) -> RWS r w1 s a1 -> RWS r w2 s a2
45+
mapRWS :: forall r w1 w2 s a1 a2. (RWSResult s a1 w1 -> RWSResult s a2 w2) -> RWS r w1 s a1 -> RWS r w2 s a2
4646
mapRWS f = mapRWST (runIdentity >>> f >>> Identity)
4747

4848
-- | Change the type of the context in a `RWS` action

src/Control/Monad/RWS/Trans.purs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- | This module defines the reader-writer-state monad transformer, `RWST`.
22

33
module Control.Monad.RWS.Trans
4-
( See()
4+
( RWSResult(..)
55
, RWST(..), runRWST, evalRWST, execRWST, mapRWST, withRWST
66
, module Control.Monad.Trans
77
, module Control.Monad.RWS.Class
@@ -22,69 +22,69 @@ import Control.Monad.State.Class
2222
import Control.Monad.Trans
2323
import Control.Monad.Writer.Class
2424

25-
data See state result writer = See state result writer
25+
data RWSResult state result writer = RWSResult state result writer
2626

2727
-- | The reader-writer-state monad transformer, which combines the operations
2828
-- | of `ReaderT`, `WriterT` and `StateT` into a single monad transformer.
29-
newtype RWST r w s m a = RWST (r -> s -> m (See s a w))
29+
newtype RWST r w s m a = RWST (r -> s -> m (RWSResult s a w))
3030

3131
-- | Run a computation in the `RWST` monad.
32-
runRWST :: forall r w s m a. RWST r w s m a -> r -> s -> m (See s a w)
32+
runRWST :: forall r w s m a. RWST r w s m a -> r -> s -> m (RWSResult s a w)
3333
runRWST (RWST x) = x
3434

3535
-- | Run a computation in the `RWST` monad, discarding the final state.
3636
evalRWST :: forall r w s m a. (Monad m) => RWST r w s m a -> r -> s -> m (Tuple a w)
37-
evalRWST m r s = runRWST m r s >>= \(See _ result writer) -> return (Tuple result writer)
37+
evalRWST m r s = runRWST m r s >>= \(RWSResult _ result writer) -> return (Tuple result writer)
3838

3939
-- | Run a computation in the `RWST` monad, discarding the result.
4040
execRWST :: forall r w s m a. (Monad m) => RWST r w s m a -> r -> s -> m (Tuple s w)
41-
execRWST m r s = runRWST m r s >>= \(See state _ writer) -> return (Tuple state writer)
41+
execRWST m r s = runRWST m r s >>= \(RWSResult state _ writer) -> return (Tuple state writer)
4242

4343
-- | Change the result and accumulator types in a `RWST` monad action.
44-
mapRWST :: forall r w1 w2 s m1 m2 a1 a2. (m1 (See s a1 w1) -> m2 (See s a2 w2)) -> RWST r w1 s m1 a1 -> RWST r w2 s m2 a2
44+
mapRWST :: forall r w1 w2 s m1 m2 a1 a2. (m1 (RWSResult s a1 w1) -> m2 (RWSResult s a2 w2)) -> RWST r w1 s m1 a1 -> RWST r w2 s m2 a2
4545
mapRWST f m = RWST \r s -> f $ runRWST m r s
4646

4747
-- | Change the context type in a `RWST` monad action.
4848
withRWST :: forall r1 r2 w s m a. (r2 -> s -> Tuple r1 s) -> RWST r1 w s m a -> RWST r2 w s m a
4949
withRWST f m = RWST \r s -> uncurry (runRWST m) (f r s)
5050

5151
instance functorRWST :: (Functor m, Monoid w) => Functor (RWST r w s m) where
52-
map f m = RWST \r s -> (\(See state result writer) -> See state (f result) writer) <$> runRWST m r s
52+
map f m = RWST \r s -> (\(RWSResult state result writer) -> RWSResult state (f result) writer) <$> runRWST m r s
5353

5454
instance applyRWST :: (Bind m, Monoid w) => Apply (RWST r w s m) where
5555
apply f m = RWST \r s ->
56-
runRWST f r s >>= \(See s' f' w') ->
57-
runRWST m r s' <#> \(See s'' a'' w'') ->
58-
See s'' (f' a'') (w' ++ w'')
56+
runRWST f r s >>= \(RWSResult s' f' w') ->
57+
runRWST m r s' <#> \(RWSResult s'' a'' w'') ->
58+
RWSResult s'' (f' a'') (w' ++ w'')
5959

6060
instance bindRWST :: (Bind m, Monoid w) => Bind (RWST r w s m) where
6161
bind m f = RWST \r s ->
62-
runRWST m r s >>= \(See s' a w) ->
63-
runRWST (f a) r s' <#> \(See state result writer) ->
64-
See state result (w ++ writer)
62+
runRWST m r s >>= \(RWSResult s' a w) ->
63+
runRWST (f a) r s' <#> \(RWSResult state result writer) ->
64+
RWSResult state result (w ++ writer)
6565

6666
instance applicativeRWST :: (Monad m, Monoid w) => Applicative (RWST r w s m) where
67-
pure a = RWST \_ s -> pure $ See s a mempty
67+
pure a = RWST \_ s -> pure $ RWSResult s a mempty
6868

6969
instance monadRWST :: (Monad m, Monoid w) => Monad (RWST r w s m)
7070

7171
instance monadTransRWST :: (Monoid w) => MonadTrans (RWST r w s) where
72-
lift m = RWST \_ s -> m >>= \a -> return $ See s a mempty
72+
lift m = RWST \_ s -> m >>= \a -> return $ RWSResult s a mempty
7373

7474
instance monadEffRWS :: (Monad m, Monoid w, MonadEff eff m) => MonadEff eff (RWST r w s m) where
7575
liftEff = lift <<< liftEff
7676

7777
instance monadReaderRWST :: (Monad m, Monoid w) => MonadReader r (RWST r w s m) where
78-
ask = RWST \r s -> pure $ See s r mempty
78+
ask = RWST \r s -> pure $ RWSResult s r mempty
7979
local f m = RWST \r s -> runRWST m (f r) s
8080

8181
instance monadStateRWST :: (Monad m, Monoid w) => MonadState s (RWST r w s m) where
82-
state f = RWST \_ s -> case f s of Tuple a s' -> pure $ See s' a mempty
82+
state f = RWST \_ s -> case f s of Tuple a s' -> pure $ RWSResult s' a mempty
8383

8484
instance monadWriterRWST :: (Monad m, Monoid w) => MonadWriter w (RWST r w s m) where
85-
writer (Tuple a w) = RWST \_ s -> pure $ See s a w
86-
listen m = RWST \r s -> runRWST m r s >>= \(See s' a w) -> pure $ See s' (Tuple a w) w
87-
pass m = RWST \r s -> runRWST m r s >>= \(See s' (Tuple a f) w) -> pure $ See s' a (f w)
85+
writer (Tuple a w) = RWST \_ s -> pure $ RWSResult s a w
86+
listen m = RWST \r s -> runRWST m r s >>= \(RWSResult s' a w) -> pure $ RWSResult s' (Tuple a w) w
87+
pass m = RWST \r s -> runRWST m r s >>= \(RWSResult s' (Tuple a f) w) -> pure $ RWSResult s' a (f w)
8888

8989
instance monadRWSRWST :: (Monad m, Monoid w) => MonadRWS r w s (RWST r w s m)
9090

@@ -93,10 +93,10 @@ instance monadErrorRWST :: (MonadError e m, Monoid w) => MonadError e (RWST r w
9393
catchError m h = RWST $ \r s -> catchError (runRWST m r s) (\e -> runRWST (h e) r s)
9494

9595
instance monadRecRWST :: (Monoid w, MonadRec m) => MonadRec (RWST r w s m) where
96-
tailRecM k a = RWST \r s -> tailRecM (k' r) (See s a mempty)
96+
tailRecM k a = RWST \r s -> tailRecM (k' r) (RWSResult s a mempty)
9797
where
98-
k' r (See state result writer) = do
99-
See state' result' writer' <- runRWST (k result) r state
98+
k' r (RWSResult state result writer) = do
99+
RWSResult state' result' writer' <- runRWST (k result) r state
100100
return case result' of
101-
Left a -> Left (See state' a (writer <> writer'))
102-
Right b -> Right (See state' b (writer <> writer'))
101+
Left a -> Left (RWSResult state' a (writer <> writer'))
102+
Right b -> Right (RWSResult state' b (writer <> writer'))

0 commit comments

Comments
 (0)