Skip to content

Commit e2294ad

Browse files
committed
Updates for RC
1 parent ea5deb5 commit e2294ad

24 files changed

+1879
-162
lines changed

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,26 @@ Monad and comonad transformers based on [mtl](http://hackage.haskell.org/package
88

99
## Documentation
1010

11+
- [Control.Monad.Trans](docs/Control.Monad.Trans.md)
12+
- [Control.Comonad.Trans](docs/Control.Comonad.Trans.md)
13+
1114
### Monad Transformers
1215

13-
- [MonadTrans](docs/Control.Monad.Trans.md)
14-
- [Errors](docs/Control.Monad.Error.md)
15-
- [Exceptions](docs/Monad/Except.md)
16-
- [Maybe](docs/Control.Monad.Maybe.md)
17-
- [State](docs/Control.Monad.State.md)
18-
- [Writer](docs/Control.Monad.Writer.md)
19-
- [Reader](docs/Control.Monad.Reader.md)
20-
- [Reader/Writer/State](docs/Control.Monad.RWS.md)
21-
- [CPS](docs/Control.Monad.Cont.md)
16+
- [Control.Monad.Cont](docs/Control.Monad.Cont.md) (Continuations)
17+
18+
- [Control.Monad.Error](docs/Control.Monad.Error.md)
19+
- [Control.Monad.Except](docs/Control.Monad.Except.md)
20+
21+
- [Control.Monad.List.Trans](docs/Control.Monad.List.Trans.md)
22+
- [Control.Monad.Maybe.Trans](docs/Control.Monad.Maybe.Trans.md)
23+
24+
- [Control.Monad.Reader](docs/Control.Monad.Reader.md)
25+
- [Control.Monad.Writer](docs/Control.Monad.Writer.md)
26+
- [Control.Monad.State](docs/Control.Monad.State.md)
27+
- [Control.Monad.RWS](docs/Control.Monad.RWS.md) (Reader/Writer/State)
2228

2329
### Comonad Transformers
2430

25-
- [ComonadTrans](docs/Control.Comonad.Trans.md)
26-
- [Environment](docs/Control.Comonad.Env.md)
27-
- [Store](docs/Control.Comonad.Store.md)
28-
- [Cowriter](docs/Control.Comonad.Traced.md)
31+
- [Control.Comonad.Env](docs/Control.Comonad.Env.md) (Environment or "Coreader")
32+
- [Control.Comonad.Store](docs/Control.Comonad.Store.md) (or "Costate")
33+
- [Control.Comonad.Traced](docs/Control.Comonad.Traced.md) (or "Cowriter")

bower.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
"package.json"
3232
],
3333
"dependencies": {
34-
"purescript-tailrec": "~0.3.0"
34+
"purescript-lazy": "^0.4.0",
35+
"purescript-tailrec": "^0.3.0",
36+
"purescript-unfoldable": "^0.4.0"
3537
},
3638
"devDependencies": {
37-
"purescript-console": "~0.1.0"
39+
"purescript-console": "^0.1.0"
3840
}
3941
}

docs/Control.Comonad.Env.md

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,90 @@
1+
## Module Control.Comonad.Env
2+
3+
This module defines the `Env` comonad.
4+
5+
#### `Env`
6+
7+
``` purescript
8+
type Env e = EnvT e Identity
9+
```
10+
11+
The `Env` comonad is a synonym for the `EnvT` comonad transformer, applied
12+
to the `Identity` monad.
13+
14+
#### `runEnv`
15+
16+
``` purescript
17+
runEnv :: forall e a. Env e a -> Tuple e a
18+
```
19+
20+
Unwrap a value in the `Env` comonad.
21+
22+
#### `withEnv`
23+
24+
``` purescript
25+
withEnv :: forall e1 e2 a. (e1 -> e2) -> Env e1 a -> Env e2 a
26+
```
27+
28+
Change the environment type in an `Env` computation.
29+
30+
#### `mapEnv`
31+
32+
``` purescript
33+
mapEnv :: forall e a b. (a -> b) -> Env e a -> Env e b
34+
```
35+
36+
Change the data type in an `Env` computation.
37+
38+
#### `env`
39+
40+
``` purescript
41+
env :: forall e a. e -> a -> Env e a
42+
```
43+
44+
Create a value in context in the `Env` comonad.
45+
46+
47+
## Module Control.Comonad.Env.Class
48+
49+
This module defines the `ComonadEnv` type class and its instances.
50+
51+
#### `ComonadEnv`
52+
53+
``` purescript
54+
class (Comonad w) <= ComonadEnv e w where
55+
ask :: forall a. w a -> e
56+
local :: forall a. (e -> e) -> w a -> w a
57+
```
58+
59+
The `ComonadEnv` type class represents those monads which support a global environment via
60+
`ask` and `local`.
61+
62+
- `ask` reads the current environment from the context.
63+
- `local` changes the value of the global environment.
64+
65+
An implementation is provided for `EnvT`.
66+
67+
Laws:
68+
69+
- `ask (local f x) = f (ask x)`
70+
- `extract (local _ x) = extract a`
71+
- `extend g (local f x) = extend (g <<< local f) x`
72+
73+
##### Instances
74+
``` purescript
75+
instance comonadEnvTuple :: ComonadEnv e (Tuple e)
76+
instance comonadEnvEnvT :: (Comonad w) => ComonadEnv e (EnvT e w)
77+
```
78+
79+
#### `asks`
80+
81+
``` purescript
82+
asks :: forall e1 e2 w a. (ComonadEnv e1 w) => (e1 -> e2) -> w e1 -> e2
83+
```
84+
85+
Get a value which depends on the environment.
86+
87+
188
## Module Control.Comonad.Env.Trans
289

390
This module defines the environment comonad transformer, `EnvT`.
@@ -9,6 +96,13 @@ newtype EnvT e w a
996
= EnvT (Tuple e (w a))
1097
```
1198

99+
The environment comonad transformer.
100+
101+
This comonad transformer extends the context of a value in the base comonad with a _global environment_ of
102+
type `e`.
103+
104+
The `ComonadEnv` type class describes the operations supported by this comonad.
105+
12106
##### Instances
13107
``` purescript
14108
instance functorEnvT :: (Functor w) => Functor (EnvT e w)
@@ -17,13 +111,6 @@ instance comonadEnvT :: (Comonad w) => Comonad (EnvT e w)
17111
instance comonadTransEnvT :: ComonadTrans (EnvT e)
18112
```
19113

20-
The environment comonad transformer.
21-
22-
This comonad transformer extends the context of a value in the base comonad with a _global environment_ of
23-
type `e`.
24-
25-
The `ComonadEnv` type class describes the operations supported by this comonad.
26-
27114
#### `runEnvT`
28115

29116
``` purescript

docs/Control.Comonad.Store.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
## Module Control.Comonad.Store
2+
3+
This module defines the `Store` comonad.
4+
5+
#### `Store`
6+
7+
``` purescript
8+
type Store s a = StoreT s Identity a
9+
```
10+
11+
The `Store` comonad is a synonym for the `StoreT` comonad transformer, applied
12+
to the `Identity` monad.
13+
14+
#### `runStore`
15+
16+
``` purescript
17+
runStore :: forall s a. Store s a -> Tuple (s -> a) s
18+
```
19+
20+
Unwrap a value in the `Store` comonad.
21+
22+
#### `store`
23+
24+
``` purescript
25+
store :: forall s a. (s -> a) -> s -> Store s a
26+
```
27+
28+
Create a value in context in the `Store` comonad.
29+
30+
31+
## Module Control.Comonad.Store.Class
32+
33+
This module defines the `ComonadStore` type class and its instances.
34+
35+
#### `ComonadStore`
36+
37+
``` purescript
38+
class (Comonad w) <= ComonadStore s w where
39+
pos :: forall a. w a -> s
40+
peek :: forall a. s -> w a -> a
41+
```
42+
43+
The `ComonadStore` type class represents those monads which support local position information via
44+
`pos` and `peek`.
45+
46+
- `pos` reads the current position.
47+
- `peek` reads the value at the specified position in the specified context.
48+
49+
An implementation is provided for `StoreT`.
50+
51+
Laws:
52+
53+
- `pos (extend _ x) = pos x`
54+
- `peek (pos x) x = extract x`
55+
56+
For example:
57+
58+
```purescript
59+
blur :: forall w. (ComonadStore Number w) -> w Number -> w Number
60+
blur = extend \r -> (peeks (\n -> n - 1) r + peeks (\n -> n + 1) r) / 2)
61+
```
62+
63+
##### Instances
64+
``` purescript
65+
instance comonadStoreStoreT :: (Comonad w) => ComonadStore s (StoreT s w)
66+
```
67+
68+
#### `experiment`
69+
70+
``` purescript
71+
experiment :: forall f a w s. (ComonadStore s w, Functor f) => (s -> f s) -> w a -> f a
72+
```
73+
74+
Extract a collection of values from positions which depend on the current position.
75+
76+
#### `peeks`
77+
78+
``` purescript
79+
peeks :: forall s a w. (ComonadStore s w) => (s -> s) -> w a -> a
80+
```
81+
82+
Extract a value from a position which depends on the current position.
83+
84+
#### `seek`
85+
86+
``` purescript
87+
seek :: forall s a w. (ComonadStore s w, Extend w) => s -> w a -> w a
88+
```
89+
90+
Reposition the focus at the specified position.
91+
92+
#### `seeks`
93+
94+
``` purescript
95+
seeks :: forall s a w. (ComonadStore s w, Extend w) => (s -> s) -> w a -> w a
96+
```
97+
98+
Reposition the focus at the specified position, which depends on the current position.
99+
100+
101+
## Module Control.Comonad.Store.Trans
102+
103+
This module defines the store comonad transformer, `StoreT`.
104+
105+
#### `StoreT`
106+
107+
``` purescript
108+
newtype StoreT s w a
109+
= StoreT (Tuple (w (s -> a)) s)
110+
```
111+
112+
The store comonad transformer.
113+
114+
This comonad transformer extends the context of a value in the base comonad so that the value
115+
depends on a position of type `s`.
116+
117+
The `ComonadStore` type class describes the operations supported by this comonad.
118+
119+
##### Instances
120+
``` purescript
121+
instance functorStoreT :: (Functor w) => Functor (StoreT s w)
122+
instance extendStoreT :: (Extend w) => Extend (StoreT s w)
123+
instance comonadStoreT :: (Comonad w) => Comonad (StoreT s w)
124+
instance comonadTransStoreT :: ComonadTrans (StoreT s)
125+
```
126+
127+
#### `runStoreT`
128+
129+
``` purescript
130+
runStoreT :: forall s w a. StoreT s w a -> Tuple (w (s -> a)) s
131+
```
132+
133+
Unwrap a value in the `StoreT` comonad.
134+
135+

0 commit comments

Comments
 (0)