@@ -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,12 +163,9 @@ 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+An infix alias for `cons`.
166−1 : [2, 3, 4] = [1, 2, 3, 4]
168+Note, the running time of this function is `O(n)`.
170#### `cons`
170#### `cons`
@@ -173,6 +173,13 @@ Attaches an element to the front of a list.
173cons :: forall a. a -> [a] -> [a]
173cons :: forall a. a -> [a] -> [a]
176+Attaches an element to the front of an array, creating a new array.
179+cons 1 [2, 3, 4] = [1, 2, 3, 4]
182+Note, the running time of this function is `O(n)`.
177#### `Show`
184#### `Show`
@@ -181,6 +188,10 @@ class Show a where
181 show :: a -> String
188 show :: a -> String
191+The `Show` type class represents those types which can be converted into a human-readable `String` representation.
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`.
185#### `showUnit`
196#### `showUnit`
@@ -224,10 +235,12 @@ class Functor f where
224 (<$>) :: forall a b. (a -> b) -> f a -> f b
235 (<$>) :: 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
238+A `Functor` is a type constructor which supports a mapping operation `(<$>)`.
228−between [`Category`](#category)s that preserves structure.
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.
230−`Functor`s should obey the following rules.
243+`Functor` instances should satisfy the following laws:
232- Identity: `(<$>) id = id`
245- Identity: `(<$>) id = id`
233- Composition: `(<$>) (f <<< g) = (<$> f) <<< (<$> g)`
246- Composition: `(<$>) (f <<< g) = (<$> f) <<< (<$> g)`
@@ -239,6 +252,11 @@ between [`Category`](#category)s that preserves structure.
239(<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
252(<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
255+`(<#>)` is `(<$>)` with its arguments flipped. For example:
258+[1, 2, 3] <#> \n -> n * n
243#### `void`
261#### `void`
@@ -246,6 +264,16 @@ between [`Category`](#category)s that preserves structure.
246void :: forall f a. (Functor f) => f a -> f Unit
264void :: forall f a. (Functor f) => f a -> f Unit
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.
270+`void` is often useful when using `do` notation to change the return type of a monadic computation:
273+main = forE 1 10 \n -> void do
250#### `Apply`
278#### `Apply`
@@ -254,13 +282,24 @@ class (Functor f) <= Apply f where
254 (<*>) :: forall a b. f (a -> b) -> f a -> f b
282 (<*>) :: forall a b. f (a -> b) -> f a -> f b
257−`Apply`s are intuitively [`Applicative`](#applicative)s less `pure`, and more formally a
285+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.
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:
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
295+`(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts the function application operator `($)` to arguments
296+wrapped with the type constructor `f`.
260−`Apply`s should obey the following rule.
298+`Apply` instances should satisfy the following law:
262- Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
300- Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
302+Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
265#### `Applicative`
304#### `Applicative`
@@ -269,10 +308,14 @@ class (Apply f) <= Applicative f where
269 pure :: forall a. a -> f a
308 pure :: forall a. a -> f a
272−`Applicative`s are [`Functor`](#functor)s which can be "applied" by sequencing composition
311+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`).
312+create values of type `f a` from values of type `a`.
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.
275−`Applicative`s should obey the following rules.
318+`Applicative` instances should satisfy the following laws:
277- Identity: `(pure id) <*> v = v`
320- Identity: `(pure id) <*> v = v`
278- Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
321- Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
@@ -286,6 +329,15 @@ class (Apply f) <= Applicative f where
286liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
329liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
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.
335+`liftA1` can therefore be used to write [`Functor`](#functor) instances as follows:
338+instance functorF :: Functor F where
290#### `Bind`
342#### `Bind`
@@ -294,12 +346,33 @@ class (Apply m) <= Bind m where
294 (>>=) :: forall a b. m a -> (a -> m b) -> m b
346 (>>=) :: 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.
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.
352+The `>>=` operator can also be expressed using `do` notation, as follows:
359+where the function argument of `f` is given the name `y`.
361+`Bind` instances should satisfy the following law:
299−`Bind`s should obey the following rule.
363+- Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
301−- Associativity: `forall f g x. (x >>= f) >>= g = x >>= (\k => f k >>= g)`
365+Or, expressed using `do` notation:
367+- Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
369+Associativity tells us that we can regroup operations which use do-notation, so that we can unambiguously write, for example:
304#### `Monad`
377#### `Monad`
@@ -307,14 +380,19 @@ A `Bind` is an [`Apply`](#apply) with a bind operation which sequentially compos
307class (Applicative m, Bind m) <= Monad m where
380class (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
383+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.
384+represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
313−`Monad`s should obey the following rules.
386+`Monad` instances should satisfy the following laws:
315- Left Identity: `pure x >>= f = f x`
388- Left Identity: `pure x >>= f = f x`
316- Right Identity: `x >>= pure = x`
389- Right Identity: `x >>= pure = x`
391+Or, expressed using `do` notation:
393+- Left Identity: `do { y <- pure x ; f y } = f x`
394+- Right Identity: `do { y <- x ; pure y } = x`
319#### `return`
397#### `return`
@@ -322,6 +400,7 @@ more formally though of as a monoid in the category of endofunctors.
322return :: forall m a. (Monad m) => a -> m a
400return :: forall m a. (Monad m) => a -> m a
403+`return` is an alias for `pure`.
326#### `liftM1`
405#### `liftM1`
@@ -329,6 +408,15 @@ return :: forall m a. (Monad m) => a -> m a
329liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
408liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
411+`liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
412+without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
414+`liftM1` can therefore be used to write [`Functor`](#functor) instances as follows:
417+instance functorF :: Functor F where
@@ -336,6 +424,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
424ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
427+`ap` provides a default implementation of `(<*>)` for any [`Monad`](#monad),
428+without using `(<*>)` as provided by the [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
430+`ap` can therefore be used to write [`Apply`](#apply) instances as follows:
433+instance applyF :: Apply F where
340#### `functorArr`
437#### `functorArr`
@@ -384,8 +481,8 @@ class Semiring a where
385Addition and multiplication, satisfying the following laws:
482Addition and multiplication, satisfying the following laws:
387−- `a` is a commutative monoid under addition with identity element zero
484+- `a` is a commutative monoid under addition
388−- `a` is a monoid under multiplication with identity element one
485+- `a` is a monoid under multiplication
389- multiplication distributes over addition
486- multiplication distributes over addition
390- multiplication by `zero` annihilates `a`
487- multiplication by `zero` annihilates `a`
@@ -485,6 +582,10 @@ newtype Unit
485 = Unit { }
582 = Unit { }
585+The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
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.
489#### `unit`
590#### `unit`
@@ -492,6 +593,7 @@ newtype Unit
492unit :: Unit
593unit :: Unit
596+`unit` is the sole inhabitant of the `Unit` type.
@@ -501,7 +603,16 @@ class Eq a where
501 (/=) :: a -> a -> Boolean
603 (/=) :: a -> a -> Boolean
504−Class for types that have an equality comparison.
606+The `Eq` type class represents types which support decidable equality.
608+`Eq` instances should satisfy the following laws:
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)`
615+`(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
506#### `refEq`
617#### `refEq`
@@ -561,6 +672,11 @@ data Ordering
675+The `Ordering` data type represents the three possible outcomes of comparing two values:
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.
565#### `eqOrdering`
681#### `eqOrdering`
@@ -590,9 +706,9 @@ class (Eq a) <= Ord a where
590 compare :: a -> a -> Ordering
706 compare :: a -> a -> Ordering
593−Class for types that have ordered comparisons.
709+The `Ord` type class represents types which support comparisons.
595−Represents a partially ordered set satisfying the following laws:
711+`Ord` instances should satisfy the laws of _partially orderings_:
597- Reflexivity: `a <= a`
713- Reflexivity: `a <= a`
598- Antisymmetry: if `a <= b` and `b <= a` then `a = b`
714- Antisymmetry: if `a <= b` and `b <= a` then `a = b`
@@ -605,6 +721,7 @@ Represents a partially ordered set satisfying the following laws:
605(<) :: forall a. (Ord a) => a -> a -> Boolean
721(<) :: forall a. (Ord a) => a -> a -> Boolean
724+Test whether one value is _strictly less than_ another.
609#### `(>)`
726#### `(>)`
@@ -612,6 +729,7 @@ Represents a partially ordered set satisfying the following laws:
612(>) :: forall a. (Ord a) => a -> a -> Boolean
729(>) :: forall a. (Ord a) => a -> a -> Boolean
732+Test whether one value is _strictly greater than_ another.
616#### `(<=)`
734#### `(<=)`
@@ -619,6 +737,7 @@ Represents a partially ordered set satisfying the following laws:
619(<=) :: forall a. (Ord a) => a -> a -> Boolean
737(<=) :: forall a. (Ord a) => a -> a -> Boolean
740+Test whether one value is _non-strictly less than_ another.
623#### `(>=)`
742#### `(>=)`
@@ -626,6 +745,7 @@ Represents a partially ordered set satisfying the following laws:
626(>=) :: forall a. (Ord a) => a -> a -> Boolean
745(>=) :: forall a. (Ord a) => a -> a -> Boolean
748+Test whether one value is _non-strictly greater than_ another.
630#### `ordUnit`
750#### `ordUnit`
@@ -675,6 +795,7 @@ class Bits b where
675 complement :: b -> b
795 complement :: b -> b
798+The `Bits` type class identifies types which support bitwise operations.
679#### `bitsNumber`
800#### `bitsNumber`
@@ -692,6 +813,10 @@ class BoolLike b where
692 not :: b -> b
813 not :: b -> b
816+The `BoolLike` type class identifies types which support Boolean operations.
818+`BoolLike` instances are required to satisfy the laws of a _Boolean algebra_.
696#### `boolLikeBoolean`
821#### `boolLikeBoolean`
@@ -707,6 +832,13 @@ class Semigroup a where
707 (<>) :: a -> a -> a
832 (<>) :: a -> a -> a
835+The `Semigroup` type class identifies an associative operation on a type.
837+`Semigroup` instances are required to satisfy the following law:
839+- Associativity: `(x <> y) <> z = x <> (y <> z)`
841+For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
711#### `semigroupUnit`
843#### `semigroupUnit`
@@ -735,6 +867,7 @@ instance semigroupArr :: (Semigroup s') => Semigroup (s -> s')
735(++) :: forall s. (Semigroup s) => s -> s -> s
867(++) :: forall s. (Semigroup s) => s -> s -> s
870+`(++)` is an alias for `(<>)`.
740## Module Data.Function
873## Module Data.Function