@@ -72,6 +72,8 @@ element `id`, just composable morphisms.
7272
7373- Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
7474
75+One example of a `Semigroupoid` is the function type constructor `(->)`, with `(<<<)` defined
76+as function composition.
7577
7678#### `semigroupoidArr`
7779
@@ -86,6 +88,7 @@ instance semigroupoidArr :: Semigroupoid Prim.Function
8688(>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
8789```
8890
91+Forwards composition, or `(<<<)` with its arguments reversed.
8992
9093#### `Category`
9194
@@ -160,12 +163,9 @@ length (groupBy productCategory (filter isInStock (products)))
160163(:) :: forall a. a -> [a] -> [a]
161164```
162165
163−Attaches an element to the front of a list.
164−
165−```purescript
166−1 : [2, 3, 4] = [1, 2, 3, 4]
167−```
166+An infix alias for `cons`.
168167
168+Note, the running time of this function is `O(n)`.
169169
170170#### `cons`
171171
@@ -173,6 +173,13 @@ Attaches an element to the front of a list.
173173cons :: forall a. a -> [a] -> [a]
174174```
175175
176+Attaches an element to the front of an array, creating a new array.
177+
178+```purescript
179+cons 1 [2, 3, 4] = [1, 2, 3, 4]
180+```
181+
182+Note, the running time of this function is `O(n)`.
176183
177184#### `Show`
178185
@@ -181,6 +188,10 @@ class Show a where
181188 show :: a -> String
182189```
183190
191+The `Show` type class represents those types which can be converted into a human-readable `String` representation.
192+
193+While not required, it is recommended that for any expression `x`, the string `show x` be executable PureScript code
194+which evaluates to the same value as the expression `x`.
184195
185196#### `showUnit`
186197
@@ -224,10 +235,12 @@ class Functor f where
224235 (<$>) :: forall a b. (a -> b) -> f a -> f b
225236```
226237
227−A `Functor` is intuitively a type which can be mapped over, and more formally a mapping
228−between [`Category`](#category)s that preserves structure.
238+A `Functor` is a type constructor which supports a mapping operation `(<$>)`.
239+
240+`(<$>)` can be used to turn functions `a -> b` into functions `f a -> f b` whose argument and return
241+types use the type constructor `f` to represent some computational context.
229242
230−`Functor`s should obey the following rules.
243+`Functor` instances should satisfy the following laws:
231244
232245- Identity: `(<$>) id = id`
233246- Composition: `(<$>) (f <<< g) = (<$> f) <<< (<$> g)`
@@ -239,6 +252,11 @@ between [`Category`](#category)s that preserves structure.
239252(<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
240253```
241254
255+`(<#>)` is `(<$>)` with its arguments flipped. For example:
256+
257+```purescript
258+[1, 2, 3] <#> \n -> n * n
259+```
242260
243261#### `void`
244262
@@ -246,6 +264,16 @@ between [`Category`](#category)s that preserves structure.
246264void :: forall f a. (Functor f) => f a -> f Unit
247265```
248266
267+The `void` function is used to ignore the type wrapped by a [`Functor`](#functor), replacing it with `Unit` and
268+keeping only the type information provided by the type constructor itself.
269+
270+`void` is often useful when using `do` notation to change the return type of a monadic computation:
271+
272+```purescript
273+main = forE 1 10 \n -> void do
274+ print n
275+ print (n * n)
276+```
249277
250278#### `Apply`
251279
@@ -254,13 +282,24 @@ class (Functor f) <= Apply f where
254282 (<*>) :: forall a b. f (a -> b) -> f a -> f b
255283```
256284
257−`Apply`s are intuitively [`Applicative`](#applicative)s less `pure`, and more formally a
258−strong lax semi-monoidal endofunctor.
285+The `Apply` class provides the `(<*>)` which is used to apply a function to an argument under a type constructor.
286+
287+`Apply` can be used to lift functions of two or more arguments to work on values wrapped with the type constructor `f`.
288+It might also be understood in terms of the `lift2` function:
289+
290+```purescript
291+lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
292+lift2 f a b = f <$> a <*> b
293+```
294+
295+`(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts the function application operator `($)` to arguments
296+wrapped with the type constructor `f`.
259297
260−`Apply`s should obey the following rule.
298+`Apply` instances should satisfy the following law:
261299
262300- Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
263301
302+Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
264303
265304#### `Applicative`
266305
@@ -269,10 +308,14 @@ class (Apply f) <= Applicative f where
269308 pure :: forall a. a -> f a
270309```
271310
272−`Applicative`s are [`Functor`](#functor)s which can be "applied" by sequencing composition
273−(`<*>`) or embedding pure expressions (`pure`).
311+The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
312+create values of type `f a` from values of type `a`.
274313
275−`Applicative`s should obey the following rules.
314+Where [`Apply`](#apply) provides the ability to lift functions of two or more arguments to functions whose arguments are wrapped using `f`,
315+and [`Functor`](#functor) provides the ability to lift functions of one argument, `pure` can be seen as the function which lifts functions of
316+_zero_ arguments. That is, `Applicative` functors support a lifting operation for any number of function arguments.
317+
318+`Applicative` instances should satisfy the following laws:
276319
277320- Identity: `(pure id) <*> v = v`
278321- Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
@@ -286,6 +329,15 @@ class (Apply f) <= Applicative f where
286329liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
287330```
288331
332+`liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
333+without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
334+
335+`liftA1` can therefore be used to write [`Functor`](#functor) instances as follows:
336+
337+```purescript
338+instance functorF :: Functor F where
339+ (<$>) = liftA1
340+```
289341
290342#### `Bind`
291343
@@ -294,12 +346,33 @@ class (Apply m) <= Bind m where
294346 (>>=) :: forall a b. m a -> (a -> m b) -> m b
295347```
296348
297−A `Bind` is an [`Apply`](#apply) with a bind operation which sequentially composes actions.
349+The `Bind` type class extends the [`Apply`](#apply) type class with a "bind" operation `(>>=)` which composes computations
350+in sequence, using the return value of one computation to determine the next computation.
351+
352+The `>>=` operator can also be expressed using `do` notation, as follows:
353+
354+```purescript
355+x >>= f = do y <- x
356+ f y
357+```
358+
359+where the function argument of `f` is given the name `y`.
360+
361+`Bind` instances should satisfy the following law:
298362
299−`Bind`s should obey the following rule.
363+- Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
300364
301−- Associativity: `forall f g x. (x >>= f) >>= g = x >>= (\k => f k >>= g)`
365+Or, expressed using `do` notation:
302366
367+- Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
368+
369+Associativity tells us that we can regroup operations which use do-notation, so that we can unambiguously write, for example:
370+
371+```purescript
372+do x <- m1
373+ y <- m2 x
374+ m3 x y
375+```
303376
304377#### `Monad`
305378
@@ -307,14 +380,19 @@ A `Bind` is an [`Apply`](#apply) with a bind operation which sequentially compos
307380class (Applicative m, Bind m) <= Monad m where
308381```
309382
310−`Monad` is a class which can be intuitively thought of as an abstract datatype of actions or
311−more formally though of as a monoid in the category of endofunctors.
383+The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
384+represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
312385
313−`Monad`s should obey the following rules.
386+`Monad` instances should satisfy the following laws:
314387
315388- Left Identity: `pure x >>= f = f x`
316389- Right Identity: `x >>= pure = x`
317390
391+Or, expressed using `do` notation:
392+
393+- Left Identity: `do { y <- pure x ; f y } = f x`
394+- Right Identity: `do { y <- x ; pure y } = x`
395+
318396
319397#### `return`
320398
@@ -322,6 +400,7 @@ more formally though of as a monoid in the category of endofunctors.
322400return :: forall m a. (Monad m) => a -> m a
323401```
324402
403+`return` is an alias for `pure`.
325404
326405#### `liftM1`
327406
@@ -329,6 +408,15 @@ return :: forall m a. (Monad m) => a -> m a
329408liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
330409```
331410
411+`liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
412+without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
413+
414+`liftM1` can therefore be used to write [`Functor`](#functor) instances as follows:
415+
416+```purescript
417+instance functorF :: Functor F where
418+ (<$>) = liftM1
419+```
332420
333421#### `ap`
334422
@@ -336,6 +424,15 @@ liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
336424ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
337425```
338426
427+`ap` provides a default implementation of `(<*>)` for any [`Monad`](#monad),
428+without using `(<*>)` as provided by the [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
429+
430+`ap` can therefore be used to write [`Apply`](#apply) instances as follows:
431+
432+```purescript
433+instance applyF :: Apply F where
434+ (<*>) = ap
435+```
339436
340437#### `functorArr`
341438
@@ -384,8 +481,8 @@ class Semiring a where
384481
385482Addition and multiplication, satisfying the following laws:
386483
387−- `a` is a commutative monoid under addition with identity element zero
388−- `a` is a monoid under multiplication with identity element one
484+- `a` is a commutative monoid under addition
485+- `a` is a monoid under multiplication
389486- multiplication distributes over addition
390487- multiplication by `zero` annihilates `a`
391488
@@ -485,6 +582,10 @@ newtype Unit
485582 = Unit { }
486583```
487584
585+The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
586+
587+`Unit` is often used, wrapped in a monadic type constructor, as the return type of a computation where only
588+the _effects_ are important.
488589
489590#### `unit`
490591
@@ -492,6 +593,7 @@ newtype Unit
492593unit :: Unit
493594```
494595
596+`unit` is the sole inhabitant of the `Unit` type.
495597
496598#### `Eq`
497599
@@ -501,7 +603,16 @@ class Eq a where
501603 (/=) :: a -> a -> Boolean
502604```
503605
504−Class for types that have an equality comparison.
606+The `Eq` type class represents types which support decidable equality.
607+
608+`Eq` instances should satisfy the following laws:
609+
610+- Reflexivity: `x == x = true`
611+- Symmetry: `x == y = y == x`
612+- Transitivity: if `x == y` and `y == z` then `x == z`
613+- Negation: `x /= y = not (x == y)`
614+
615+`(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
505616
506617#### `refEq`
507618
@@ -561,6 +672,11 @@ data Ordering
561672 | EQ
562673```
563674
675+The `Ordering` data type represents the three possible outcomes of comparing two values:
676+
677+`LT` - The first value is _less than_ the second.
678+`GT` - The first value is _greater than_ the second.
679+`EQ` - The first value is _equal to_ or _incomparable to_ the second.
564680
565681#### `eqOrdering`
566682
@@ -590,9 +706,9 @@ class (Eq a) <= Ord a where
590706 compare :: a -> a -> Ordering
591707```
592708
593−Class for types that have ordered comparisons.
709+The `Ord` type class represents types which support comparisons.
594710
595−Represents a partially ordered set satisfying the following laws:
711+`Ord` instances should satisfy the laws of _partially orderings_:
596712
597713- Reflexivity: `a <= a`
598714- Antisymmetry: if `a <= b` and `b <= a` then `a = b`
@@ -605,6 +721,7 @@ Represents a partially ordered set satisfying the following laws:
605721(<) :: forall a. (Ord a) => a -> a -> Boolean
606722```
607723
724+Test whether one value is _strictly less than_ another.
608725
609726#### `(>)`
610727
@@ -612,6 +729,7 @@ Represents a partially ordered set satisfying the following laws:
612729(>) :: forall a. (Ord a) => a -> a -> Boolean
613730```
614731
732+Test whether one value is _strictly greater than_ another.
615733
616734#### `(<=)`
617735
@@ -619,6 +737,7 @@ Represents a partially ordered set satisfying the following laws:
619737(<=) :: forall a. (Ord a) => a -> a -> Boolean
620738```
621739
740+Test whether one value is _non-strictly less than_ another.
622741
623742#### `(>=)`
624743
@@ -626,6 +745,7 @@ Represents a partially ordered set satisfying the following laws:
626745(>=) :: forall a. (Ord a) => a -> a -> Boolean
627746```
628747
748+Test whether one value is _non-strictly greater than_ another.
629749
630750#### `ordUnit`
631751
@@ -675,6 +795,7 @@ class Bits b where
675795 complement :: b -> b
676796```
677797
798+The `Bits` type class identifies types which support bitwise operations.
678799
679800#### `bitsNumber`
680801
@@ -692,6 +813,10 @@ class BoolLike b where
692813 not :: b -> b
693814```
694815
816+The `BoolLike` type class identifies types which support Boolean operations.
817+
818+`BoolLike` instances are required to satisfy the laws of a _Boolean algebra_.
819+
695820
696821#### `boolLikeBoolean`
697822
@@ -707,6 +832,13 @@ class Semigroup a where
707832 (<>) :: a -> a -> a
708833```
709834
835+The `Semigroup` type class identifies an associative operation on a type.
836+
837+`Semigroup` instances are required to satisfy the following law:
838+
839+- Associativity: `(x <> y) <> z = x <> (y <> z)`
840+
841+For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
710842
711843#### `semigroupUnit`
712844
@@ -735,6 +867,7 @@ instance semigroupArr :: (Semigroup s') => Semigroup (s -> s')
735867(++) :: forall s. (Semigroup s) => s -> s -> s
736868```
737869
870+`(++)` is an alias for `(<>)`.
738871
739872
740873## Module Data.Function