@@ -72,6 +72,8 @@ element `id`, just composable morphisms.
73- Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
73- Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
75+One example of a `Semigroupoid` is the function type constructor `(->)`, with `(<<<)` defined
76+as function composition.
76#### `semigroupoidArr`
78#### `semigroupoidArr`
@@ -86,6 +88,7 @@ instance semigroupoidArr :: Semigroupoid Prim.Function
86(>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
88(>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
91+Forwards composition, or `(<<<)` with its arguments reversed.
90#### `Category`
93#### `Category`
@@ -160,13 +163,12 @@ length (groupBy productCategory (filter isInStock (products)))
160(:) :: forall a. a -> [a] -> [a]
163(:) :: forall a. a -> [a] -> [a]
163−Attaches an element to the front of a list.
166+Attaches an element to the front of an array, creating a new array.
165```purescript
168```purescript
1661 : [2, 3, 4] = [1, 2, 3, 4]
1691 : [2, 3, 4] = [1, 2, 3, 4]
170#### `cons`
172#### `cons`
172``` purescript
174``` purescript
@@ -181,6 +183,10 @@ class Show a where
181 show :: a -> String
183 show :: a -> String
186+The `Show` type class represents those types which can be converted into a human-readable `String` representation.
188+While not required, it is recommended that for any expression `x`, the string `show x` be executable PureScript code
189+which evaluates to the same value as the expression `x`.
185#### `showUnit`
191#### `showUnit`
@@ -224,10 +230,12 @@ class Functor f where
224 (<$>) :: forall a b. (a -> b) -> f a -> f b
230 (<$>) :: forall a b. (a -> b) -> f a -> f b
227−A `Functor` is intuitively a type which can be mapped over, and more formally a mapping
233+A `Functor` is a type constructor which supports a mapping operation `(<$>)`.
228−between [`Category`](#category)s that preserves structure.
235+`(<$>)` can be used to turn functions `a -> b` into functions `f a -> f b` whose argument and return
236+types use the type constructor `f` to represent some computational context.
230−`Functor`s should obey the following rules.
238+`Functor` instances should satisfy the following laws:
232- Identity: `(<$>) id = id`
240- Identity: `(<$>) id = id`
233- Composition: `(<$>) (f <<< g) = (<$> f) <<< (<$> g)`
241- Composition: `(<$>) (f <<< g) = (<$> f) <<< (<$> g)`
@@ -239,6 +247,11 @@ between [`Category`](#category)s that preserves structure.
239(<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
247(<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
250+`(<#>)` is `(<$>)` with its arguments flipped. For example:
253+[1, 2, 3] <#> \n -> n * n
243#### `void`
256#### `void`
@@ -246,6 +259,16 @@ between [`Category`](#category)s that preserves structure.
246void :: forall f a. (Functor f) => f a -> f Unit
259void :: forall f a. (Functor f) => f a -> f Unit
262+The `void` function is used to ignore the type wrapped by a [`Functor`](#functor), replacing it with `Unit` and
263+keeping only the type information provided by the type constructor itself.
265+`void` is often useful when using `do` notation to change the return type of a monadic computation:
268+main = forE 1 10 \n -> void do
250#### `Apply`
273#### `Apply`
@@ -254,13 +277,24 @@ class (Functor f) <= Apply f where
254 (<*>) :: forall a b. f (a -> b) -> f a -> f b
277 (<*>) :: forall a b. f (a -> b) -> f a -> f b
257−`Apply`s are intuitively [`Applicative`](#applicative)s less `pure`, and more formally a
280+The `Apply` class provides the `(<*>)` which is used to apply a function to an argument under a type constructor.
258−strong lax semi-monoidal endofunctor.
282+`Apply` can be used to lift functions of two or more arguments to work on values wrapped with the type constructor `f`.
283+It might also be understood in terms of the `lift2` function:
286+lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
287+lift2 f a b = f <$> a <*> b
290+`(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts the function application operator `($)` to arguments
291+wrapped with the type constructor `f`.
260−`Apply`s should obey the following rule.
293+`Apply` instances should satisfy the following law:
262- Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
295- Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
297+Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
265#### `Applicative`
299#### `Applicative`
@@ -269,10 +303,14 @@ class (Apply f) <= Applicative f where
269 pure :: forall a. a -> f a
303 pure :: forall a. a -> f a
272−`Applicative`s are [`Functor`](#functor)s which can be "applied" by sequencing composition
306+The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
273−(`<*>`) or embedding pure expressions (`pure`).
307+create values of type `f a` from values of type `a`.
309+Where [`Apply`](#apply) provides the ability to lift functions of two or more arguments to functions whose arguments are wrapped using `f`,
310+and [`Functor`](#functor) provides the ability to lift functions of one argument, `pure` can be seen as the function which lifts functions of
311+_zero_ arguments. That is, `Applicative` functors support a lifting operation for any number of function arguments.
275−`Applicative`s should obey the following rules.
313+`Applicative` instances should satisfy the following laws:
277- Identity: `(pure id) <*> v = v`
315- Identity: `(pure id) <*> v = v`
278- Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
316- Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
@@ -286,6 +324,15 @@ class (Apply f) <= Applicative f where
286liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
324liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
327+`liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
328+without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
330+`liftA1` can therefore be used to write [`Functor`](#functor) instances as follows:
333+instance functorF :: Functor F where
290#### `Bind`
337#### `Bind`
@@ -294,12 +341,33 @@ class (Apply m) <= Bind m where
294 (>>=) :: forall a b. m a -> (a -> m b) -> m b
341 (>>=) :: forall a b. m a -> (a -> m b) -> m b
297−A `Bind` is an [`Apply`](#apply) with a bind operation which sequentially composes actions.
344+The `Bind` type class extends the [`Apply`](#apply) type class with a "bind" operation `(>>=)` which composes computations
345+in sequence, using the return value of one computation to determine the next computation.
347+The `>>=` operator can also be expressed using `do` notation, as follows:
354+where the function argument of `f` is given the name `y`.
299−`Bind`s should obey the following rule.
356+`Bind` instances should satisfy the following law:
301- Associativity: `forall f g x. (x >>= f) >>= g = x >>= (\k => f k >>= g)`
358- Associativity: `forall f g x. (x >>= f) >>= g = x >>= (\k => f k >>= g)`
360+Or, expressed using `do` notation:
362+- Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
364+Associativity tells us that we can regroup operations which use do-notation, so that we can unambiguously write, for example:
304#### `Monad`
372#### `Monad`
@@ -307,14 +375,19 @@ A `Bind` is an [`Apply`](#apply) with a bind operation which sequentially compos
307class (Applicative m, Bind m) <= Monad m where
375class (Applicative m, Bind m) <= Monad m where
310−`Monad` is a class which can be intuitively thought of as an abstract datatype of actions or
378+The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
311−more formally though of as a monoid in the category of endofunctors.
379+represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
313−`Monad`s should obey the following rules.
381+`Monad` instances should satisfy the following laws:
315- Left Identity: `pure x >>= f = f x`
383- Left Identity: `pure x >>= f = f x`
316- Right Identity: `x >>= pure = x`
384- Right Identity: `x >>= pure = x`
386+Or, expressed using `do` notation:
388+- Left Identity: `do { y <- pure x ; f y } = f x`
389+- Right Identity: `do { y <- x ; pure y } = x`
319#### `return`
392#### `return`
@@ -322,6 +395,7 @@ more formally though of as a monoid in the category of endofunctors.
322return :: forall m a. (Monad m) => a -> m a
395return :: forall m a. (Monad m) => a -> m a
398+`return` is an alias for `pure`.
326#### `liftM1`
400#### `liftM1`
@@ -329,6 +403,15 @@ return :: forall m a. (Monad m) => a -> m a
329liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
403liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
406+`liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
407+without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
409+`liftM1` can therefore be used to write [`Functor`](#functor) instances as follows:
412+instance functorF :: Functor F where
@@ -336,6 +419,15 @@ liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
336ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
419ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
422+`ap` provides a default implementation of `(<*>)` for any [`Monad`](#monad),
423+without using `(<*>)` as provided by the [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
425+`ap` can therefore be used to write [`Apply`](#apply) instances as follows:
428+instance applyF :: Apply F where
340#### `functorArr`
432#### `functorArr`
@@ -384,8 +476,8 @@ class Semiring a where
385Addition and multiplication, satisfying the following laws:
477Addition and multiplication, satisfying the following laws:
387−- `a` is a commutative monoid under addition with identity element zero
479+- `a` is a commutative monoid under addition
388−- `a` is a monoid under multiplication with identity element one
480+- `a` is a monoid under multiplication
389- multiplication distributes over addition
481- multiplication distributes over addition
390- multiplication by `zero` annihilates `a`
482- multiplication by `zero` annihilates `a`
@@ -485,6 +577,10 @@ newtype Unit
485 = Unit { }
577 = Unit { }
580+The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
582+`Unit` is often used, wrapped in a monadic type constructor, as the return type of a computation where only
583+the _effects_ are important.
489#### `unit`
585#### `unit`
@@ -492,6 +588,7 @@ newtype Unit
492unit :: Unit
588unit :: Unit
591+`unit` is the sole inhabitant of the `Unit` type.
@@ -501,7 +598,16 @@ class Eq a where
501 (/=) :: a -> a -> Boolean
598 (/=) :: a -> a -> Boolean
504−Class for types that have an equality comparison.
601+The `Eq` type class represents types which support decidable equality.
603+`Eq` instances should satisfy the following laws:
605+- Reflexivity: `forall x. x == x = true`
606+- Symmetry: `forall x y. x == y = y == x`
607+- Transitivity: if `x == y` and `y == z` then `x == z`
608+- Negation: `forall x y. x /= y = not (x == y)`
610+`(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
506#### `refEq`
612#### `refEq`
@@ -561,6 +667,11 @@ data Ordering
670+The `Ordering` data type represents the three possible outcomes of comparing two values:
672+`LT` - The first value is _less than_ the second.
673+`GT` - The first value is _greater than_ the second.
674+`EQ` - The first value is _equal to_ or _incomparable to_ the second.
565#### `eqOrdering`
676#### `eqOrdering`
@@ -590,9 +701,9 @@ class (Eq a) <= Ord a where
590 compare :: a -> a -> Ordering
701 compare :: a -> a -> Ordering
593−Class for types that have ordered comparisons.
704+The `Ord` type class represents types which support comparisons.
595−Represents a partially ordered set satisfying the following laws:
706+`Ord` instances should satisfy the laws of _partially orderings_:
597- Reflexivity: `a <= a`
708- Reflexivity: `a <= a`
598- Antisymmetry: if `a <= b` and `b <= a` then `a = b`
709- Antisymmetry: if `a <= b` and `b <= a` then `a = b`
@@ -605,6 +716,7 @@ Represents a partially ordered set satisfying the following laws:
605(<) :: forall a. (Ord a) => a -> a -> Boolean
716(<) :: forall a. (Ord a) => a -> a -> Boolean
719+Test whether one value is _strictly less than_ another.
609#### `(>)`
721#### `(>)`
@@ -612,6 +724,7 @@ Represents a partially ordered set satisfying the following laws:
612(>) :: forall a. (Ord a) => a -> a -> Boolean
724(>) :: forall a. (Ord a) => a -> a -> Boolean
727+Test whether one value is _strictly greater than_ another.
616#### `(<=)`
729#### `(<=)`
@@ -619,6 +732,7 @@ Represents a partially ordered set satisfying the following laws:
619(<=) :: forall a. (Ord a) => a -> a -> Boolean
732(<=) :: forall a. (Ord a) => a -> a -> Boolean
735+Test whether one value is _non-strictly less than_ another.
623#### `(>=)`
737#### `(>=)`
@@ -626,6 +740,7 @@ Represents a partially ordered set satisfying the following laws:
626(>=) :: forall a. (Ord a) => a -> a -> Boolean
740(>=) :: forall a. (Ord a) => a -> a -> Boolean
743+Test whether one value is _non-strictly greater than_ another.
630#### `ordUnit`
745#### `ordUnit`
@@ -675,6 +790,7 @@ class Bits b where
675 complement :: b -> b
790 complement :: b -> b
793+The `Bits` type class identifies types which support bitwise operations.
679#### `bitsNumber`
795#### `bitsNumber`
@@ -692,6 +808,10 @@ class BoolLike b where
692 not :: b -> b
808 not :: b -> b
811+The `BoolLike` type class identifies types which support Boolean operations.
813+`BoolLike` instances are required to satisfy the laws of a _Boolean algebra_.
696#### `boolLikeBoolean`
816#### `boolLikeBoolean`
@@ -707,6 +827,13 @@ class Semigroup a where
707 (<>) :: a -> a -> a
827 (<>) :: a -> a -> a
830+The `Semigroup` type class identifies an associative operation on a type.
832+`Semigroup` instances are required to satisfy the following law:
834+- Associativity: `forall x y z. (x <> y) <> z = x <> (y <> z)`
836+For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
711#### `semigroupUnit`
838#### `semigroupUnit`
@@ -735,6 +862,7 @@ instance semigroupArr :: (Semigroup s') => Semigroup (s -> s')
735(++) :: forall s. (Semigroup s) => s -> s -> s
862(++) :: forall s. (Semigroup s) => s -> s -> s
865+`(++)` is an alias for `(<>)`.
740## Module Data.Function
868## Module Data.Function