Skip to content

Commit 3a2bfda

Browse files
committed
Docs
1 parent 658813b commit 3a2bfda

File tree

6 files changed

+211
-76
lines changed

6 files changed

+211
-76
lines changed

README.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,47 @@
22

33
## Module Control.Comonad.Cofree
44

5+
6+
The _cofree comonad_ for a `Functor`.
7+
58
#### `Cofree`
69

710
``` purescript
811
data Cofree f a
912
```
1013

14+
The `Cofree` `Comonad` for a functor.
15+
16+
A value of type `Cofree f a` consists of an `f`-branching
17+
tree, annotated with labels of type `a`.
18+
19+
The `Comonad` instance supports _redecoration_, recomputing
20+
labels from the local context.
1121

1222
#### `mkCofree`
1323

1424
``` purescript
1525
mkCofree :: forall f a. a -> f (Cofree f a) -> Cofree f a
1626
```
1727

28+
Create a value of type `Cofree f a` from a label and a
29+
functor-full of "subtrees".
1830

1931
#### `head`
2032

2133
``` purescript
2234
head :: forall f a. Cofree f a -> a
2335
```
2436

37+
Returns the label for a tree.
2538

2639
#### `tail`
2740

2841
``` purescript
2942
tail :: forall f a. Cofree f a -> f (Cofree f a)
3043
```
3144

45+
Returns the "subtrees" of a tree.
3246

3347
#### `functorCofree`
3448

@@ -105,13 +119,18 @@ data Free f a
105119
| Gosub (forall s. (forall r. (Unit -> Free f r) -> (r -> Free f a) -> s) -> s)
106120
```
107121

122+
The free `Monad` for a `Functor`.
123+
124+
The implementation defers the evaluation of monadic binds so that it
125+
is safe to use monadic tail recursion, for example.
108126

109127
#### `FreeC`
110128

111129
``` purescript
112130
type FreeC f = Free (Coyoneda f)
113131
```
114132

133+
The free `Monad` for an arbitrary type constructor.
115134

116135
#### `MonadFree`
117136

@@ -120,6 +139,10 @@ class MonadFree f m where
120139
wrap :: forall a. f (m a) -> m a
121140
```
122141

142+
The `MonadFree` class provides the `wrap` function, which lifts
143+
actions described by a generating functor into a monad.
144+
145+
The canonical instance of `MonadFree f` is `Free f`.
123146

124147
#### `functorFree`
125148

@@ -176,41 +199,54 @@ instance monadFreeFree :: (Functor f) => MonadFree f (Free f)
176199
liftF :: forall f m a. (Functor f, Monad m, MonadFree f m) => f a -> m a
177200
```
178201

202+
Lift an action described by the generating functor `f` into the monad `m`
203+
(usually `Free f`).
179204

180205
#### `pureF`
181206

182207
``` purescript
183208
pureF :: forall f a. (Applicative f) => a -> Free f a
184209
```
185210

211+
An implementation of `pure` for the `Free` monad.
186212

187213
#### `liftFC`
188214

189215
``` purescript
190216
liftFC :: forall f a. f a -> FreeC f a
191217
```
192218

219+
Lift an action described by the generating type constructor `f` into the monad
220+
`FreeC f`.
193221

194222
#### `pureFC`
195223

196224
``` purescript
197225
pureFC :: forall f a. (Applicative f) => a -> FreeC f a
198226
```
199227

228+
An implementation of `pure` for the `FreeC` monad.
200229

201230
#### `mapF`
202231

203232
``` purescript
204233
mapF :: forall f g a. (Functor f, Functor g) => Natural f g -> Free f a -> Free g a
205234
```
206235

236+
Use a natural transformation to change the generating functor of a `Free` monad.
207237

208238
#### `injC`
209239

210240
``` purescript
211241
injC :: forall f g a. (Inject f g) => FreeC f a -> FreeC g a
212242
```
213243

244+
Embed computations in one `Free` monad as computations in the `Free` monad for
245+
a coproduct type constructor.
246+
247+
This construction allows us to write computations which are polymorphic in the
248+
particular `Free` monad we use, allowing us to extend the functionality of
249+
our monad later.
214250

215251
#### `runFree`
216252

@@ -251,47 +287,61 @@ hence we have no requirement that `f` be a `Functor`.
251287

252288
## Module Control.Monad.Trampoline
253289

290+
291+
A _trampoline_ monad, which can be used at the bottom of
292+
a monad transformer stack to avoid stack overflows in large
293+
monadic computations.
294+
254295
#### `Trampoline`
255296

256297
``` purescript
257298
type Trampoline = Free Lazy
258299
```
259300

301+
The `Trampoline` monad
302+
303+
A computation of type `Trampoline a` consists of zero or more lazy
304+
suspensions before a value is returned.
260305

261306
#### `done`
262307

263308
``` purescript
264309
done :: forall a. a -> Trampoline a
265310
```
266311

312+
Return a value immediately
267313

268314
#### `suspend`
269315

270316
``` purescript
271317
suspend :: forall a. Trampoline a -> Trampoline a
272318
```
273319

320+
Suspend a computation by one step.
274321

275322
#### `delay'`
276323

277324
``` purescript
278325
delay' :: forall a. Lazy a -> Trampoline a
279326
```
280327

328+
Use the `Trampoline` monad to represent a `Lazy` value.
281329

282330
#### `delay`
283331

284332
``` purescript
285333
delay :: forall a. (Unit -> a) -> Trampoline a
286334
```
287335

336+
Use the `Trampoline` monad to represent the delayed evaluation of a value.
288337

289338
#### `runTrampoline`
290339

291340
``` purescript
292341
runTrampoline :: forall a. Trampoline a -> a
293342
```
294343

344+
Run a computation in the `Trampoline` monad.
295345

296346

297347
## Module Data.Coyoneda
@@ -303,6 +353,9 @@ newtype CoyonedaF f a i
303353
= CoyonedaF { fi :: f i, k :: i -> a }
304354
```
305355

356+
`Coyoneda` is encoded as an existential type using `Data.Exists`.
357+
358+
This type constructor encodes the contents of the existential package.
306359

307360
#### `Coyoneda`
308361

@@ -311,13 +364,18 @@ newtype Coyoneda f a
311364
= Coyoneda (Exists (CoyonedaF f a))
312365
```
313366

367+
The `Coyoneda` `Functor`.
368+
369+
`Coyoneda f` is a `Functor` for any type constructor `f`. In fact,
370+
it is the _free_ `Functor` for `f`.
314371

315372
#### `Natural`
316373

317374
``` purescript
318375
type Natural f g = forall a. f a -> g a
319376
```
320377

378+
A natural transformation
321379

322380
#### `functorCoyoneda`
323381

@@ -381,20 +439,23 @@ instance comonadCoyoneda :: (Comonad w) => Comonad (Coyoneda w)
381439
coyoneda :: forall f a b. (a -> b) -> f a -> Coyoneda f b
382440
```
383441

442+
Construct a value of type `Coyoneda f a`.
384443

385444
#### `liftCoyoneda`
386445

387446
``` purescript
388447
liftCoyoneda :: forall f a. f a -> Coyoneda f a
389448
```
390449

450+
Lift a value described by the type constructor `f` to `Coyoneda f`.
391451

392452
#### `lowerCoyoneda`
393453

394454
``` purescript
395455
lowerCoyoneda :: forall f a. (Functor f) => Coyoneda f a -> f a
396456
```
397457

458+
Lower a value of type `Yoneda f a` to the `Functor` `f`.
398459

399460
#### `liftCoyonedaT`
400461

@@ -420,6 +481,9 @@ newtype Yoneda f a
420481
= Yoneda (forall b. (a -> b) -> f b)
421482
```
422483

484+
The Yoneda `Functor`
485+
486+
`Yoneda f` is a `Functor` for any type constructor `f`.
423487

424488
#### `functorYoneda`
425489

@@ -483,16 +547,21 @@ instance comonadYoneda :: (Comonad w) => Comonad (Yoneda w)
483547
runYoneda :: forall f a b. Yoneda f a -> (a -> b) -> f b
484548
```
485549

550+
Run a computation of type `Yoneda f a`.
486551

487552
#### `liftYoneda`
488553

489554
``` purescript
490555
liftYoneda :: forall f a. (Functor f) => f a -> Yoneda f a
491556
```
492557

558+
Lift a value described by the `Functor` `f` to the
559+
`Functor` `Yoneda f`.
493560

494561
#### `lowerYoneda`
495562

496563
``` purescript
497564
lowerYoneda :: forall f a. Yoneda f a -> f a
498-
```
565+
```
566+
567+
Lower a value of type `Yoneda f a` to the type constructor `f`.

0 commit comments

Comments
 (0)