2
2
3
3
## Module Control.Comonad.Cofree
4
4
5
+
6
+ The _ cofree comonad_ for a ` Functor ` .
7
+
5
8
#### ` Cofree `
6
9
7
10
``` purescript
8
11
data Cofree f a
9
12
```
10
13
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.
11
21
12
22
#### ` mkCofree `
13
23
14
24
``` purescript
15
25
mkCofree :: forall f a. a -> f (Cofree f a) -> Cofree f a
16
26
```
17
27
28
+ Create a value of type ` Cofree f a ` from a label and a
29
+ functor-full of "subtrees".
18
30
19
31
#### ` head `
20
32
21
33
``` purescript
22
34
head :: forall f a. Cofree f a -> a
23
35
```
24
36
37
+ Returns the label for a tree.
25
38
26
39
#### ` tail `
27
40
28
41
``` purescript
29
42
tail :: forall f a. Cofree f a -> f (Cofree f a)
30
43
```
31
44
45
+ Returns the "subtrees" of a tree.
32
46
33
47
#### ` functorCofree `
34
48
@@ -105,13 +119,18 @@ data Free f a
105
119
| Gosub (forall s. (forall r. (Unit -> Free f r) -> (r -> Free f a) -> s) -> s)
106
120
```
107
121
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.
108
126
109
127
#### ` FreeC `
110
128
111
129
``` purescript
112
130
type FreeC f = Free (Coyoneda f)
113
131
```
114
132
133
+ The free ` Monad ` for an arbitrary type constructor.
115
134
116
135
#### ` MonadFree `
117
136
@@ -120,6 +139,10 @@ class MonadFree f m where
120
139
wrap :: forall a. f (m a) -> m a
121
140
```
122
141
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 ` .
123
146
124
147
#### ` functorFree `
125
148
@@ -176,41 +199,54 @@ instance monadFreeFree :: (Functor f) => MonadFree f (Free f)
176
199
liftF :: forall f m a. (Functor f, Monad m, MonadFree f m) => f a -> m a
177
200
```
178
201
202
+ Lift an action described by the generating functor ` f ` into the monad ` m `
203
+ (usually ` Free f ` ).
179
204
180
205
#### ` pureF `
181
206
182
207
``` purescript
183
208
pureF :: forall f a. (Applicative f) => a -> Free f a
184
209
```
185
210
211
+ An implementation of ` pure ` for the ` Free ` monad.
186
212
187
213
#### ` liftFC `
188
214
189
215
``` purescript
190
216
liftFC :: forall f a. f a -> FreeC f a
191
217
```
192
218
219
+ Lift an action described by the generating type constructor ` f ` into the monad
220
+ ` FreeC f ` .
193
221
194
222
#### ` pureFC `
195
223
196
224
``` purescript
197
225
pureFC :: forall f a. (Applicative f) => a -> FreeC f a
198
226
```
199
227
228
+ An implementation of ` pure ` for the ` FreeC ` monad.
200
229
201
230
#### ` mapF `
202
231
203
232
``` purescript
204
233
mapF :: forall f g a. (Functor f, Functor g) => Natural f g -> Free f a -> Free g a
205
234
```
206
235
236
+ Use a natural transformation to change the generating functor of a ` Free ` monad.
207
237
208
238
#### ` injC `
209
239
210
240
``` purescript
211
241
injC :: forall f g a. (Inject f g) => FreeC f a -> FreeC g a
212
242
```
213
243
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.
214
250
215
251
#### ` runFree `
216
252
@@ -251,47 +287,61 @@ hence we have no requirement that `f` be a `Functor`.
251
287
252
288
## Module Control.Monad.Trampoline
253
289
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
+
254
295
#### ` Trampoline `
255
296
256
297
``` purescript
257
298
type Trampoline = Free Lazy
258
299
```
259
300
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.
260
305
261
306
#### ` done `
262
307
263
308
``` purescript
264
309
done :: forall a. a -> Trampoline a
265
310
```
266
311
312
+ Return a value immediately
267
313
268
314
#### ` suspend `
269
315
270
316
``` purescript
271
317
suspend :: forall a. Trampoline a -> Trampoline a
272
318
```
273
319
320
+ Suspend a computation by one step.
274
321
275
322
#### ` delay' `
276
323
277
324
``` purescript
278
325
delay' :: forall a. Lazy a -> Trampoline a
279
326
```
280
327
328
+ Use the ` Trampoline ` monad to represent a ` Lazy ` value.
281
329
282
330
#### ` delay `
283
331
284
332
``` purescript
285
333
delay :: forall a. (Unit -> a) -> Trampoline a
286
334
```
287
335
336
+ Use the ` Trampoline ` monad to represent the delayed evaluation of a value.
288
337
289
338
#### ` runTrampoline `
290
339
291
340
``` purescript
292
341
runTrampoline :: forall a. Trampoline a -> a
293
342
```
294
343
344
+ Run a computation in the ` Trampoline ` monad.
295
345
296
346
297
347
## Module Data.Coyoneda
@@ -303,6 +353,9 @@ newtype CoyonedaF f a i
303
353
= CoyonedaF { fi :: f i, k :: i -> a }
304
354
```
305
355
356
+ ` Coyoneda ` is encoded as an existential type using ` Data.Exists ` .
357
+
358
+ This type constructor encodes the contents of the existential package.
306
359
307
360
#### ` Coyoneda `
308
361
@@ -311,13 +364,18 @@ newtype Coyoneda f a
311
364
= Coyoneda (Exists (CoyonedaF f a))
312
365
```
313
366
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 ` .
314
371
315
372
#### ` Natural `
316
373
317
374
``` purescript
318
375
type Natural f g = forall a. f a -> g a
319
376
```
320
377
378
+ A natural transformation
321
379
322
380
#### ` functorCoyoneda `
323
381
@@ -381,20 +439,23 @@ instance comonadCoyoneda :: (Comonad w) => Comonad (Coyoneda w)
381
439
coyoneda :: forall f a b. (a -> b) -> f a -> Coyoneda f b
382
440
```
383
441
442
+ Construct a value of type ` Coyoneda f a ` .
384
443
385
444
#### ` liftCoyoneda `
386
445
387
446
``` purescript
388
447
liftCoyoneda :: forall f a. f a -> Coyoneda f a
389
448
```
390
449
450
+ Lift a value described by the type constructor ` f ` to ` Coyoneda f ` .
391
451
392
452
#### ` lowerCoyoneda `
393
453
394
454
``` purescript
395
455
lowerCoyoneda :: forall f a. (Functor f) => Coyoneda f a -> f a
396
456
```
397
457
458
+ Lower a value of type ` Yoneda f a ` to the ` Functor ` ` f ` .
398
459
399
460
#### ` liftCoyonedaT `
400
461
@@ -420,6 +481,9 @@ newtype Yoneda f a
420
481
= Yoneda (forall b. (a -> b) -> f b)
421
482
```
422
483
484
+ The Yoneda ` Functor `
485
+
486
+ ` Yoneda f ` is a ` Functor ` for any type constructor ` f ` .
423
487
424
488
#### ` functorYoneda `
425
489
@@ -483,16 +547,21 @@ instance comonadYoneda :: (Comonad w) => Comonad (Yoneda w)
483
547
runYoneda :: forall f a b. Yoneda f a -> (a -> b) -> f b
484
548
```
485
549
550
+ Run a computation of type ` Yoneda f a ` .
486
551
487
552
#### ` liftYoneda `
488
553
489
554
``` purescript
490
555
liftYoneda :: forall f a. (Functor f) => f a -> Yoneda f a
491
556
```
492
557
558
+ Lift a value described by the ` Functor ` ` f ` to the
559
+ ` Functor ` ` Yoneda f ` .
493
560
494
561
#### ` lowerYoneda `
495
562
496
563
``` purescript
497
564
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