Skip to content

Commit 6ed4a54

Browse files
committed
Merge pull request #5 from purescript/docs
First stab at docs
2 parents 538035e + 79a8a0e commit 6ed4a54

File tree

10 files changed

+126
-1
lines changed

10 files changed

+126
-1
lines changed

docs/Module.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class (Biapply w) <= Biapplicative w where
99
bipure :: forall a b. a -> b -> w a b
1010
```
1111

12+
`Biapplicative` captures type constructors of two arguments which support lifting of
13+
functions of zero or more arguments, in the sense of `Applicative`.
1214

1315
#### `biapplicativeTuple`
1416

@@ -33,6 +35,12 @@ instance biapplicativeConst :: Biapplicative Const
3335
(<<$>>) :: forall a b. (a -> b) -> a -> b
3436
```
3537

38+
A convenience function which can be used to apply the result of `bipure` in
39+
the style of `Applicative`:
40+
41+
```purescript
42+
bipure f g <<$>> x <<*>> y
43+
```
3644

3745
#### `Biapply`
3846

@@ -41,34 +49,40 @@ class (Bifunctor w) <= Biapply w where
4149
(<<*>>) :: forall a b c d. w (a -> b) (c -> d) -> w a c -> w b d
4250
```
4351

52+
`Biapply` captures type constructors of two arguments which support lifting of
53+
functions of one or more arguments, in the sense of `Apply`.
4454

4555
#### `(*>>)`
4656

4757
``` purescript
4858
(*>>) :: forall w a b c d. (Biapply w) => w a b -> w c d -> w c d
4959
```
5060

61+
Keep the results of the second computation
5162

5263
#### `(<<*)`
5364

5465
``` purescript
5566
(<<*) :: forall w a b c d. (Biapply w) => w a b -> w c d -> w a b
5667
```
5768

69+
Keep the results of the first computation
5870

5971
#### `bilift2`
6072

6173
``` purescript
6274
bilift2 :: forall w a b c d e f. (Biapply w) => (a -> b -> c) -> (d -> e -> f) -> w a d -> w b e -> w c f
6375
```
6476

77+
Lift a function of two arguments.
6578

6679
#### `bilift3`
6780

6881
``` purescript
6982
bilift3 :: forall w a b c d e f g h. (Biapply w) => (a -> b -> c -> d) -> (e -> f -> g -> h) -> w a e -> w b f -> w c g -> w d h
7083
```
7184

85+
Lift a function of three arguments.
7286

7387
#### `biapplyTuple`
7488

@@ -96,6 +110,13 @@ class Bifoldable p where
96110
bifoldMap :: forall m a b. (Monoid m) => (a -> m) -> (b -> m) -> p a b -> m
97111
```
98112

113+
`Bifoldable` represents data structures with two type arguments which can be
114+
folded.
115+
116+
A fold for such a structure requires two step functions, one for each type
117+
argument. Type class instances should choose the appropriate step function based
118+
on the type of the element encountered at each point of the fold.
119+
99120

100121
#### `bifoldableTuple`
101122

@@ -124,41 +145,49 @@ instance bifoldableConst :: Bifoldable Const
124145
bifold :: forall t m. (Bifoldable t, Monoid m) => t m m -> m
125146
```
126147

148+
Fold a data structure, accumulating values in a monoidal type.
127149

128150
#### `bitraverse_`
129151

130152
``` purescript
131153
bitraverse_ :: forall t f a b c d. (Bifoldable t, Applicative f) => (a -> f c) -> (b -> f d) -> t a b -> f Unit
132154
```
133155

156+
Traverse a data structure, accumulating effects using an `Applicative` functor,
157+
ignoring the final result.
134158

135159
#### `bifor_`
136160

137161
``` purescript
138162
bifor_ :: forall t f a b c d. (Bifoldable t, Applicative f) => t a b -> (a -> f c) -> (b -> f d) -> f Unit
139163
```
140164

165+
A version of `bitraverse_` with the data structure as the first argument.
141166

142167
#### `bisequence_`
143168

144169
``` purescript
145170
bisequence_ :: forall t f a b. (Bifoldable t, Applicative f) => t (f a) (f b) -> f Unit
146171
```
147172

173+
Collapse a data structure, collecting effects using an `Applicative` functor,
174+
ignoring the final result.
148175

149176
#### `biany`
150177

151178
``` purescript
152179
biany :: forall t a b. (Bifoldable t) => (a -> Boolean) -> (b -> Boolean) -> t a b -> Boolean
153180
```
154181

182+
Test whether a predicate holds at any position in a data structure.
155183

156184
#### `biall`
157185

158186
``` purescript
159187
biall :: forall t a b. (Bifoldable t) => (a -> Boolean) -> (b -> Boolean) -> t a b -> Boolean
160188
```
161189

190+
Test whether a predicate holds at all positions in a data structure.
162191

163192

164193
## Module Data.Bifunctor
@@ -170,20 +199,35 @@ class Bifunctor f where
170199
bimap :: forall a b c d. (a -> b) -> (c -> d) -> f a c -> f b d
171200
```
172201

202+
A `Bifunctor` is a `Functor` from the pair category `(Type, Type)` to `Type`.
203+
204+
A type constructor with two type arguments can be made into a `Bifunctor` if
205+
both of its type arguments are covariant.
206+
207+
The `bimap` function maps a pair of functions over the two type arguments
208+
of the bifunctor.
209+
210+
Laws:
211+
212+
- Identity: `bimap id id == id`
213+
- Composition: `bimap f1 g1 <<< bimap f2 g2 == bimap (f1 <<< f2) (g1 <<< g2)`
214+
173215

174216
#### `lmap`
175217

176218
``` purescript
177219
lmap :: forall f a b c. (Bifunctor f) => (a -> b) -> f a c -> f b c
178220
```
179221

222+
Map a function over the first type argument of a `Bifunctor`.
180223

181224
#### `rmap`
182225

183226
``` purescript
184227
rmap :: forall f a b c. (Bifunctor f) => (b -> c) -> f a b -> f a c
185228
```
186229

230+
Map a function over the second type component of a `Bifunctor`.
187231

188232
#### `bifunctorEither`
189233

@@ -290,13 +334,16 @@ data Flip p a b
290334
= Flip (p b a)
291335
```
292336

337+
Flips the order of the type arguments of a `Bifunctor`, creating a
338+
`Functor` instance for the first type argument.
293339

294340
#### `runFlip`
295341

296342
``` purescript
297343
runFlip :: forall p a b. Flip p a b -> p b a
298344
```
299345

346+
Remove the `Flip` constructor.
300347

301348
#### `flipBifunctor`
302349

@@ -364,13 +411,16 @@ data Join p a
364411
= Join (p a a)
365412
```
366413

414+
`Join` turns a `Bifunctor` into a `Functor` by equating the
415+
two type arguments.
367416

368417
#### `runJoin`
369418

370419
``` purescript
371420
runJoin :: forall p a. Join p a -> p a a
372421
```
373422

423+
Remove the `Join` constructor.
374424

375425
#### `joinFunctor`
376426

@@ -491,6 +541,7 @@ data Product f g a b
491541
= Pair (f a b) (g a b)
492542
```
493543

544+
The product of two `Bifunctor`s.
494545

495546
#### `productBifunctor`
496547

@@ -536,13 +587,16 @@ data Wrap p a b
536587
= Wrap (p a b)
537588
```
538589

590+
A `newtype` wrapper which provides default `Functor`, `Foldable` and `Traversable`
591+
type class instances for `Bifunctor`s.
539592

540593
#### `unwrap`
541594

542595
``` purescript
543596
unwrap :: forall p a b. Wrap p a b -> p a b
544597
```
545598

599+
Remove the `Wrap` constructor.
546600

547601
#### `wrapBifunctor`
548602

@@ -611,6 +665,13 @@ class (Bifunctor t, Bifoldable t) <= Bitraversable t where
611665
bisequence :: forall f a b. (Applicative f) => t (f a) (f b) -> f (t a b)
612666
```
613667

668+
`Bitraversable` represents data structures with two type arguments which can be
669+
traversed.
670+
671+
A traversal for such a structure requires two functions, one for each type
672+
argument. Type class instances should choose the appropriate function based
673+
on the type of the element encountered at each point of the traversal.
674+
614675

615676
#### `bitraversableTuple`
616677

@@ -637,4 +698,6 @@ instance bitraversableConst :: Bitraversable Const
637698

638699
``` purescript
639700
bifor :: forall t f a b c d. (Bitraversable t, Applicative f) => t a b -> (a -> f c) -> (b -> f d) -> f (t c d)
640-
```
701+
```
702+
703+
Traverse a data structure, accumulating effects and results using an `Applicative` functor.

src/Control/Biapplicative.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import Data.Tuple
55

66
import Control.Biapply
77

8+
-- | `Biapplicative` captures type constructors of two arguments which support lifting of
9+
-- | functions of zero or more arguments, in the sense of `Applicative`.
810
class (Biapply w) <= Biapplicative w where
911
bipure :: forall a b. a -> b -> w a b
1012

src/Control/Biapply.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,33 @@ infixl 4 <<*>>
1111
infixl 4 <<*
1212
infixl 4 *>>
1313

14+
-- | A convenience function which can be used to apply the result of `bipure` in
15+
-- | the style of `Applicative`:
16+
-- |
17+
-- | ```purescript
18+
-- | bipure f g <<$>> x <<*>> y
19+
-- | ```
1420
(<<$>>) :: forall a b. (a -> b) -> a -> b
1521
(<<$>>) = id
1622

23+
-- | `Biapply` captures type constructors of two arguments which support lifting of
24+
-- | functions of one or more arguments, in the sense of `Apply`.
1725
class (Bifunctor w) <= Biapply w where
1826
(<<*>>) :: forall a b c d. w (a -> b) (c -> d) -> w a c -> w b d
1927

28+
-- | Keep the results of the second computation
2029
(*>>) :: forall w a b c d. (Biapply w) => w a b -> w c d -> w c d
2130
(*>>) a b = bimap (const id) (const id) <<$>> a <<*>> b
2231

32+
-- | Keep the results of the first computation
2333
(<<*) :: forall w a b c d. (Biapply w) => w a b -> w c d -> w a b
2434
(<<*) a b = bimap const const <<$>> a <<*>> b
2535

36+
-- | Lift a function of two arguments.
2637
bilift2 :: forall w a b c d e f. (Biapply w) => (a -> b -> c) -> (d -> e -> f) -> w a d -> w b e -> w c f
2738
bilift2 f g a b = bimap f g <<$>> a <<*>> b
2839

40+
-- | Lift a function of three arguments.
2941
bilift3 :: forall w a b c d e f g h. (Biapply w) => (a -> b -> c -> d) -> (e -> f -> g -> h) -> w a e -> w b f -> w c g -> w d h
3042
bilift3 f g a b c = bimap f g <<$>> a <<*>> b <<*>> c
3143

src/Data/Bifoldable.purs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import Data.Tuple
1010
import Control.Apply
1111
import Control.Bind
1212

13+
-- | `Bifoldable` represents data structures with two type arguments which can be
14+
-- | folded.
15+
-- |
16+
-- | A fold for such a structure requires two step functions, one for each type
17+
-- | argument. Type class instances should choose the appropriate step function based
18+
-- | on the type of the element encountered at each point of the fold.
19+
-- |
1320
class Bifoldable p where
1421
bifoldr :: forall a b c. (a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
1522
bifoldl :: forall a b c. (c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c
@@ -33,20 +40,28 @@ instance bifoldableConst :: Bifoldable Const where
3340
bifoldr f _ z (Const a) = f a z
3441
bifoldl f _ z (Const a) = f z a
3542

43+
-- | Fold a data structure, accumulating values in a monoidal type.
3644
bifold :: forall t m. (Bifoldable t, Monoid m) => t m m -> m
3745
bifold = bifoldMap id id
3846

47+
-- | Traverse a data structure, accumulating effects using an `Applicative` functor,
48+
-- | ignoring the final result.
3949
bitraverse_ :: forall t f a b c d. (Bifoldable t, Applicative f) => (a -> f c) -> (b -> f d) -> t a b -> f Unit
4050
bitraverse_ f g = bifoldr ((*>) <<< f) ((*>) <<< g) (pure unit)
4151

52+
-- | A version of `bitraverse_` with the data structure as the first argument.
4253
bifor_ :: forall t f a b c d. (Bifoldable t, Applicative f) => t a b -> (a -> f c) -> (b -> f d) -> f Unit
4354
bifor_ t f g = bitraverse_ f g t
4455

56+
-- | Collapse a data structure, collecting effects using an `Applicative` functor,
57+
-- | ignoring the final result.
4558
bisequence_ :: forall t f a b. (Bifoldable t, Applicative f) => t (f a) (f b) -> f Unit
4659
bisequence_ = bitraverse_ id id
4760

61+
-- | Test whether a predicate holds at any position in a data structure.
4862
biany :: forall t a b. (Bifoldable t) => (a -> Boolean) -> (b -> Boolean) -> t a b -> Boolean
4963
biany p q = runAny <<< bifoldMap (Any <<< p) (Any <<< q)
5064

65+
-- | Test whether a predicate holds at all positions in a data structure.
5166
biall :: forall t a b. (Bifoldable t) => (a -> Boolean) -> (b -> Boolean) -> t a b -> Boolean
5267
biall p q = runAll <<< bifoldMap (All <<< p) (All <<< q)

src/Data/Bifunctor.purs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@ import Data.Const
44
import Data.Either
55
import Data.Tuple
66

7+
-- | A `Bifunctor` is a `Functor` from the pair category `(Type, Type)` to `Type`.
8+
-- |
9+
-- | A type constructor with two type arguments can be made into a `Bifunctor` if
10+
-- | both of its type arguments are covariant.
11+
-- |
12+
-- | The `bimap` function maps a pair of functions over the two type arguments
13+
-- | of the bifunctor.
14+
-- |
15+
-- | Laws:
16+
-- |
17+
-- | - Identity: `bimap id id == id`
18+
-- | - Composition: `bimap f1 g1 <<< bimap f2 g2 == bimap (f1 <<< f2) (g1 <<< g2)`
19+
-- |
720
class Bifunctor f where
821
bimap :: forall a b c d. (a -> b) -> (c -> d) -> f a c -> f b d
922

23+
-- | Map a function over the first type argument of a `Bifunctor`.
1024
lmap :: forall f a b c. (Bifunctor f) => (a -> b) -> f a c -> f b c
1125
lmap f = bimap f id
1226

27+
-- | Map a function over the second type component of a `Bifunctor`.
1328
rmap :: forall f a b c. (Bifunctor f) => (b -> c) -> f a b -> f a c
1429
rmap = bimap id
1530

src/Data/Bifunctor/Flip.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import Control.Apply
1111
import Control.Biapplicative
1212
import Control.Biapply
1313

14+
-- | Flips the order of the type arguments of a `Bifunctor`, creating a
15+
-- | `Functor` instance for the first type argument.
1416
data Flip p a b = Flip (p b a)
1517

18+
-- | Remove the `Flip` constructor.
1619
runFlip :: forall p a b. Flip p a b -> p b a
1720
runFlip (Flip pba) = pba
1821

src/Data/Bifunctor/Join.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import Control.Apply
1111
import Control.Biapplicative
1212
import Control.Biapply
1313

14+
-- | `Join` turns a `Bifunctor` into a `Functor` by equating the
15+
-- | two type arguments.
1416
data Join p a = Join (p a a)
1517

18+
-- | Remove the `Join` constructor.
1619
runJoin :: forall p a. Join p a -> p a a
1720
runJoin (Join paa) = paa
1821

src/Data/Bifunctor/Product.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Control.Apply
1313
import Control.Biapplicative
1414
import Control.Biapply
1515

16+
-- | The product of two `Bifunctor`s.
1617
data Product f g a b = Pair (f a b) (g a b)
1718

1819
instance productBifunctor :: (Bifunctor f, Bifunctor g) => Bifunctor (Product f g) where

0 commit comments

Comments
 (0)