git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #932 from purescript/prelude-docs

Prelude documentation

commit6328c3ac232b1b8cd422a0926679284237a51000 authorPhil Freeman <paf31@cantab.net> dateMon 2 Mar 2015, 13:31 (12 years ago) parent388a3698ebc617
3 files changed+315−49
prelude/README.md+158−25 prelude/images/Prelude.png prelude/prelude.purs+157−24
prelude/README.md+158−25
@@ -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
prelude/images/Prelude.png

Binary file not shown.

prelude/prelude.purs+157−24
@@ -79,12 +79,15 @@ module Prelude
7979 -- |
8080 -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
8181 -- |
82+ -- | One example of a `Semigroupoid` is the function type constructor `(->)`, with `(<<<)` defined
83+ -- | as function composition.
8284 class Semigroupoid a where
8385 (<<<) :: forall b c d. a c d -> a b c -> a b d
8486
8587 instance semigroupoidArr :: Semigroupoid (->) where
8688 (<<<) f g x = f (g x)
8789
90+ -- | Forwards composition, or `(<<<)` with its arguments reversed.
8891 (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
8992 (>>>) f g = g <<< f
9093
@@ -143,15 +146,19 @@ module Prelude
143146
144147 infixr 6 :
145148
146− -- | Attaches an element to the front of a list.
147− -- |
148− -- | ```purescript
149− -- | 1 : [2, 3, 4] = [1, 2, 3, 4]
150− -- | ```
149+ -- | An infix alias for `cons`.
151150 -- |
151+ -- | Note, the running time of this function is `O(n)`.
152152 (:) :: forall a. a -> [a] -> [a]
153153 (:) = cons
154154
155+ -- | Attaches an element to the front of an array, creating a new array.
156+ -- |
157+ -- | ```purescript
158+ -- | cons 1 [2, 3, 4] = [1, 2, 3, 4]
159+ -- | ```
160+ -- |
161+ -- | Note, the running time of this function is `O(n)`.
155162 foreign import cons
156163 """
157164 function cons(e) {
@@ -161,6 +168,10 @@ module Prelude
161168 }
162169 """ :: forall a. a -> [a] -> [a]
163170
171+ -- | The `Show` type class represents those types which can be converted into a human-readable `String` representation.
172+ -- |
173+ -- | While not required, it is recommended that for any expression `x`, the string `show x` be executable PureScript code
174+ -- | which evaluates to the same value as the expression `x`.
164175 class Show a where
165176 show :: a -> String
166177
@@ -210,10 +221,12 @@ module Prelude
210221 infixl 4 <$>
211222 infixl 1 <#>
212223
213− -- | A `Functor` is intuitively a type which can be mapped over, and more formally a mapping
214− -- | between [`Category`](#category)s that preserves structure.
224+ -- | A `Functor` is a type constructor which supports a mapping operation `(<$>)`.
225+ -- |
226+ -- | `(<$>)` can be used to turn functions `a -> b` into functions `f a -> f b` whose argument and return
227+ -- | types use the type constructor `f` to represent some computational context.
215228 -- |
216− -- | `Functor`s should obey the following rules.
229+ -- | `Functor` instances should satisfy the following laws:
217230 -- |
218231 -- | - Identity: `(<$>) id = id`
219232 -- | - Composition: `(<$>) (f <<< g) = (<$> f) <<< (<$> g)`
@@ -221,28 +234,58 @@ module Prelude
221234 class Functor f where
222235 (<$>) :: forall a b. (a -> b) -> f a -> f b
223236
237+ -- | `(<#>)` is `(<$>)` with its arguments flipped. For example:
238+ -- |
239+ -- | ```purescript
240+ -- | [1, 2, 3] <#> \n -> n * n
241+ -- | ```
224242 (<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
225243 (<#>) fa f = f <$> fa
226244
245+ -- | The `void` function is used to ignore the type wrapped by a [`Functor`](#functor), replacing it with `Unit` and
246+ -- | keeping only the type information provided by the type constructor itself.
247+ -- |
248+ -- | `void` is often useful when using `do` notation to change the return type of a monadic computation:
249+ -- |
250+ -- | ```purescript
251+ -- | main = forE 1 10 \n -> void do
252+ -- | print n
253+ -- | print (n * n)
254+ -- | ```
227255 void :: forall f a. (Functor f) => f a -> f Unit
228256 void fa = const unit <$> fa
229257
230258 infixl 4 <*>
231259
232− -- | `Apply`s are intuitively [`Applicative`](#applicative)s less `pure`, and more formally a
233− -- | strong lax semi-monoidal endofunctor.
260+ -- | The `Apply` class provides the `(<*>)` which is used to apply a function to an argument under a type constructor.
261+ -- |
262+ -- | `Apply` can be used to lift functions of two or more arguments to work on values wrapped with the type constructor `f`.
263+ -- | It might also be understood in terms of the `lift2` function:
264+ -- |
265+ -- | ```purescript
266+ -- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
267+ -- | lift2 f a b = f <$> a <*> b
268+ -- | ```
269+ -- |
270+ -- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts the function application operator `($)` to arguments
271+ -- | wrapped with the type constructor `f`.
234272 -- |
235− -- | `Apply`s should obey the following rule.
273+ -- | `Apply` instances should satisfy the following law:
236274 -- |
237275 -- | - Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
238276 -- |
277+ -- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
239278 class (Functor f) <= Apply f where
240279 (<*>) :: forall a b. f (a -> b) -> f a -> f b
241280
242− -- | `Applicative`s are [`Functor`](#functor)s which can be "applied" by sequencing composition
243− -- | (`<*>`) or embedding pure expressions (`pure`).
281+ -- | The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
282+ -- | create values of type `f a` from values of type `a`.
283+ -- |
284+ -- | Where [`Apply`](#apply) provides the ability to lift functions of two or more arguments to functions whose arguments are wrapped using `f`,
285+ -- | and [`Functor`](#functor) provides the ability to lift functions of one argument, `pure` can be seen as the function which lifts functions of
286+ -- | _zero_ arguments. That is, `Applicative` functors support a lifting operation for any number of function arguments.
244287 -- |
245− -- | `Applicative`s should obey the following rules.
288+ -- | `Applicative` instances should satisfy the following laws:
246289 -- |
247290 -- | - Identity: `(pure id) <*> v = v`
248291 -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
@@ -252,38 +295,92 @@ module Prelude
252295 class (Apply f) <= Applicative f where
253296 pure :: forall a. a -> f a
254297
298+ -- | `liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
299+ -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
300+ -- |
301+ -- | `liftA1` can therefore be used to write [`Functor`](#functor) instances as follows:
302+ -- |
303+ -- | ```purescript
304+ -- | instance functorF :: Functor F where
305+ -- | (<$>) = liftA1
306+ -- | ```
255307 liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
256308 liftA1 f a = pure f <*> a
257309
258310 infixl 1 >>=
259311
260− -- | A `Bind` is an [`Apply`](#apply) with a bind operation which sequentially composes actions.
261− -- |
262− -- | `Bind`s should obey the following rule.
312+ -- | The `Bind` type class extends the [`Apply`](#apply) type class with a "bind" operation `(>>=)` which composes computations
313+ -- | in sequence, using the return value of one computation to determine the next computation.
314+ -- |
315+ -- | The `>>=` operator can also be expressed using `do` notation, as follows:
316+ -- |
317+ -- | ```purescript
318+ -- | x >>= f = do y <- x
319+ -- | f y
320+ -- | ```
321+ -- |
322+ -- | where the function argument of `f` is given the name `y`.
323+ -- |
324+ -- | `Bind` instances should satisfy the following law:
263325 -- |
264− -- | - Associativity: `forall f g x. (x >>= f) >>= g = x >>= (\k => f k >>= g)`
326+ -- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
265327 -- |
328+ -- | Or, expressed using `do` notation:
329+ -- |
330+ -- | - Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
331+ -- |
332+ -- | Associativity tells us that we can regroup operations which use do-notation, so that we can unambiguously write, for example:
333+ -- |
334+ -- | ```purescript
335+ -- | do x <- m1
336+ -- | y <- m2 x
337+ -- | m3 x y
338+ -- | ```
266339 class (Apply m) <= Bind m where
267340 (>>=) :: forall a b. m a -> (a -> m b) -> m b
268341
269− -- | `Monad` is a class which can be intuitively thought of as an abstract datatype of actions or
270− -- | more formally though of as a monoid in the category of endofunctors.
342+ -- | The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
343+ -- | represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
271344 -- |
272− -- | `Monad`s should obey the following rules.
345+ -- | `Monad` instances should satisfy the following laws:
273346 -- |
274347 -- | - Left Identity: `pure x >>= f = f x`
275348 -- | - Right Identity: `x >>= pure = x`
276349 -- |
350+ -- | Or, expressed using `do` notation:
351+ -- |
352+ -- | - Left Identity: `do { y <- pure x ; f y } = f x`
353+ -- | - Right Identity: `do { y <- x ; pure y } = x`
354+ -- |
277355 class (Applicative m, Bind m) <= Monad m
278356
357+ -- | `return` is an alias for `pure`.
279358 return :: forall m a. (Monad m) => a -> m a
280359 return = pure
281360
361+ -- | `liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
362+ -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
363+ -- |
364+ -- | `liftM1` can therefore be used to write [`Functor`](#functor) instances as follows:
365+ -- |
366+ -- | ```purescript
367+ -- | instance functorF :: Functor F where
368+ -- | (<$>) = liftM1
369+ -- | ```
282370 liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
283371 liftM1 f a = do
284372 a' <- a
285373 return (f a')
286374
375+ -- | `ap` provides a default implementation of `(<*>)` for any [`Monad`](#monad),
376+ -- | without using `(<*>)` as provided by the [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
377+ -- |
378+ -- | `ap` can therefore be used to write [`Apply`](#apply) instances as follows:
379+ -- |
380+ -- | ```purescript
381+ -- | instance applyF :: Apply F where
382+ -- | (<*>) = ap
383+ -- | ```
287384 ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
288385 ap f a = do
289386 f' <- f
@@ -417,15 +514,29 @@ module Prelude
417514
418515 instance numNumber :: Num Number
419516
517+ -- | The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
518+ -- |
519+ -- | `Unit` is often used, wrapped in a monadic type constructor, as the return type of a computation where only
520+ -- | the _effects_ are important.
420521 newtype Unit = Unit {}
421522
523+ -- | `unit` is the sole inhabitant of the `Unit` type.
422524 unit :: Unit
423525 unit = Unit {}
424526
425527 infix 4 ==
426528 infix 4 /=
427529
428− -- | Class for types that have an equality comparison.
530+ -- | The `Eq` type class represents types which support decidable equality.
531+ -- |
532+ -- | `Eq` instances should satisfy the following laws:
533+ -- |
534+ -- | - Reflexivity: `x == x = true`
535+ -- | - Symmetry: `x == y = y == x`
536+ -- | - Transitivity: if `x == y` and `y == z` then `x == z`
537+ -- | - Negation: `x /= y = not (x == y)`
538+ -- |
539+ -- | `(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
429540 class Eq a where
430541 (==) :: a -> a -> Boolean
431542 (/=) :: a -> a -> Boolean
@@ -483,6 +594,11 @@ module Prelude
483594 (==) xs ys = eqArrayImpl (==) xs ys
484595 (/=) xs ys = not (xs == ys)
485596
597+ -- | The `Ordering` data type represents the three possible outcomes of comparing two values:
598+ -- |
599+ -- | `LT` - The first value is _less than_ the second.
600+ -- | `GT` - The first value is _greater than_ the second.
601+ -- | `EQ` - The first value is _equal to_ or _incomparable to_ the second.
486602 data Ordering = LT | GT | EQ
487603
488604 instance eqOrdering :: Eq Ordering where
@@ -502,9 +618,9 @@ module Prelude
502618 (<>) GT _ = GT
503619 (<>) EQ y = y
504620
505− -- | Class for types that have ordered comparisons.
621+ -- | The `Ord` type class represents types which support comparisons.
506622 -- |
507− -- | Represents a partially ordered set satisfying the following laws:
623+ -- | `Ord` instances should satisfy the laws of _partially orderings_:
508624 -- |
509625 -- | - Reflexivity: `a <= a`
510626 -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
@@ -515,6 +631,7 @@ module Prelude
515631
516632 infixl 4 <
517633
634+ -- | Test whether one value is _strictly less than_ another.
518635 (<) :: forall a. (Ord a) => a -> a -> Boolean
519636 (<) a1 a2 = case a1 `compare` a2 of
520637 LT -> true
@@ -522,6 +639,7 @@ module Prelude
522639
523640 infixl 4 >
524641
642+ -- | Test whether one value is _strictly greater than_ another.
525643 (>) :: forall a. (Ord a) => a -> a -> Boolean
526644 (>) a1 a2 = case a1 `compare` a2 of
527645 GT -> true
@@ -529,6 +647,7 @@ module Prelude
529647
530648 infixl 4 <=
531649
650+ -- | Test whether one value is _non-strictly less than_ another.
532651 (<=) :: forall a. (Ord a) => a -> a -> Boolean
533652 (<=) a1 a2 = case a1 `compare` a2 of
534653 GT -> false
@@ -536,6 +655,7 @@ module Prelude
536655
537656 infixl 4 >=
538657
658+ -- | Test whether one value is _non-strictly greater than_ another.
539659 (>=) :: forall a. (Ord a) => a -> a -> Boolean
540660 (>=) a1 a2 = case a1 `compare` a2 of
541661 LT -> false
@@ -586,6 +706,7 @@ module Prelude
586706 infixl 10 .|.
587707 infixl 10 .^.
588708
709+ -- | The `Bits` type class identifies types which support bitwise operations.
589710 class Bits b where
590711 (.&.) :: b -> b -> b
591712 (.|.) :: b -> b -> b
@@ -668,6 +789,10 @@ module Prelude
668789 infixr 2 ||
669790 infixr 3 &&
670791
792+ -- | The `BoolLike` type class identifies types which support Boolean operations.
793+ -- |
794+ -- | `BoolLike` instances are required to satisfy the laws of a _Boolean algebra_.
795+ -- |
671796 class BoolLike b where
672797 (&&) :: b -> b -> b
673798 (||) :: b -> b -> b
@@ -705,6 +830,13 @@ module Prelude
705830
706831 infixr 5 <>
707832
833+ -- | The `Semigroup` type class identifies an associative operation on a type.
834+ -- |
835+ -- | `Semigroup` instances are required to satisfy the following law:
836+ -- |
837+ -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
838+ -- |
839+ -- | For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
708840 class Semigroup a where
709841 (<>) :: a -> a -> a
710842
@@ -728,6 +860,7 @@ module Prelude
728860
729861 infixr 5 ++
730862
863+ -- | `(++)` is an alias for `(<>)`.
731864 (++) :: forall s. (Semigroup s) => s -> s -> s
732865 (++) = (<>)
733866