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

Style tweaks and a few more comments

commit5205aa1b74d42d03fe67826216eafd653bbe51cc authorGary Burgess <gary.burgess@gmail.com> dateWed 25 Feb 2015, 10:45 (12 years ago) parented4fe540583227
2 files changed+88−93
prelude/README.md+44−53 prelude/prelude.purs+44−40
prelude/README.md+44−53
@@ -2,8 +2,6 @@
22
33## Module Prelude
44
5−
6−
75#### `otherwise`
86
97``` purescript
@@ -72,8 +70,7 @@ element `id`, just composable morphisms.
7270
7371`Semigroupoid`s should obey the following rule:
7472
75−Association:
76− `forall p q r. p <<< (q <<< r) = (p <<< q) <<< r`
73+- Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
7774
7875
7976#### `semigroupoidArr`
@@ -102,11 +99,8 @@ class (Semigroupoid a) <= Category a where
10299
103100`Category`s should obey the following rules.
104101
105−Left Identity:
106− `forall p. id <<< p = p`
107−
108−Right Identity:
109− `forall p. p <<< id = p`
102+- Left Identity: `id <<< p = p`
103+- Right Identity: `p <<< id = p`
110104
111105
112106#### `categoryArr`
@@ -235,11 +229,8 @@ between [`Category`](#category)s that preserves structure.
235229
236230`Functor`s should obey the following rules.
237231
238−Identity:
239− `(<$>) id = id`
240−
241−Composition:
242− `forall f g. (<$>) (f . g) = ((<$>) f) . ((<$>) g)`
232+- Identity: `(<$>) id = id`
233+- Composition: `(<$>) (f <<< g) = (<$> f) <<< (<$> g)`
243234
244235
245236#### `(<#>)`
@@ -266,10 +257,9 @@ class (Functor f) <= Apply f where
266257`Apply`s are intuitively [`Applicative`](#applicative)s less `pure`, and more formally a
267258strong lax semi-monoidal endofunctor.
268259
269−`Apply`s should obey the following rules.
260+`Apply`s should obey the following rule.
270261
271−Associative Composition:
272− `forall f g h. (.) <$> f <*> g <*> h = f <*> (g <*> h)`
262+- Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
273263
274264
275265#### `Applicative`
@@ -284,17 +274,10 @@ class (Apply f) <= Applicative f where
284274
285275`Applicative`s should obey the following rules.
286276
287−Identity:
288− `forall v. (pure id) <*> v = v`
289−
290−Composition:
291− `forall f g h. (pure (.)) <*> f <*> g <*> h = f <*> (g <*> h)`
292−
293−Homomorphism:
294− `forall f x. (pure f) <*> (pure x) = pure (f x)`
295−
296−Interchange:
297− `forall u y. u <*> (pure y) = (pure (($) y)) <*> u`
277+- Identity: `(pure id) <*> v = v`
278+- Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
279+- Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
280+- Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
298281
299282
300283#### `liftA1`
@@ -315,8 +298,7 @@ A `Bind` is an [`Apply`](#apply) with a bind operation which sequentially compos
315298
316299`Bind`s should obey the following rule.
317300
318−Associativity:
319− `forall f g x. (x >>= f) >>= g = x >>= (\k => f k >>= g)`
301+- Associativity: `forall f g x. (x >>= f) >>= g = x >>= (\k => f k >>= g)`
320302
321303
322304#### `Monad`
@@ -330,11 +312,8 @@ more formally though of as a monoid in the category of endofunctors.
330312
331313`Monad`s should obey the following rules.
332314
333−Left Identity:
334− `forall f x. pure x >>= f = f x`
335−
336−Right Identity:
337− `forall x. x >>= pure = x`
315+- Left Identity: `pure x >>= f = f x`
316+- Right Identity: `x >>= pure = x`
338317
339318
340319#### `return`
@@ -403,7 +382,13 @@ class Semiring a where
403382 one :: a
404383```
405384
406−Addition and multiplication
385+Addition and multiplication, satisfying the following laws:
386+
387+- `a` is a commutative monoid under addition
388+- `a` is a monoid under multiplication
389+- multiplication distributes over addition
390+- multiplication by `zero` annihilates `a`
391+
407392
408393#### `ModuloSemiring`
409394
@@ -413,8 +398,10 @@ class (Semiring a) <= ModuloSemiring a where
413398 mod :: a -> a -> a
414399```
415400
416−Semiring with modulo operation and division where
417−```a / b * b + (a `mod` b) = a```
401+Addition, multiplication, modulo operation and division, satisfying:
402+
403+- ```a / b * b + (a `mod` b) = a```
404+
418405
419406#### `Ring`
420407
@@ -423,7 +410,12 @@ class (Semiring a) <= Ring a where
423410 (-) :: a -> a -> a
424411```
425412
426−Addition, multiplication, and subtraction
413+Addition, multiplication, and subtraction.
414+
415+Has the same laws as `Semiring` but additionally satisfying:
416+
417+- `a` is an abelian group under addition
418+
427419
428420#### `negate`
429421
@@ -438,8 +430,10 @@ negate :: forall a. (Ring a) => a -> a
438430class (Ring a, ModuloSemiring a) <= DivisionRing a where
439431```
440432
441−Ring where every nonzero element has a multiplicative inverse (possibly
442−a non-commutative field) so that ```a `mod` b = zero```
433+Ring where every nonzero element has a multiplicative inverse so that:
434+
435+- ```a `mod` b = zero```
436+
443437
444438#### `Num`
445439
@@ -507,6 +501,7 @@ class Eq a where
507501 (/=) :: a -> a -> Boolean
508502```
509503
504+Class for types that have an equality comparison.
510505
511506#### `refEq`
512507
@@ -595,6 +590,14 @@ class (Eq a) <= Ord a where
595590 compare :: a -> a -> Ordering
596591```
597592
593+Class for types that have ordered comparisons.
594+
595+Represents a partially ordered set satisfying the following laws:
596+
597+- Reflexivity: `a <= a`
598+- Antisymmetry: if `a <= b` and `b <= a` then `a = b`
599+- Transitivity: if `a <= b` and `b <= c` then `a <= c`
600+
598601
599602#### `(<)`
600603
@@ -736,8 +739,6 @@ instance semigroupArr :: (Semigroup s') => Semigroup (s -> s')
736739
737740## Module Data.Function
738741
739−
740−
741742#### `on`
742743
743744``` purescript
@@ -979,8 +980,6 @@ runFn10 :: forall a b c d e f g h i j k. Fn10 a b c d e f g h i j k -> a -> b ->
979980
980981## Module Prelude.Unsafe
981982
982−
983−
984983#### `unsafeIndex`
985984
986985``` purescript
@@ -991,8 +990,6 @@ unsafeIndex :: forall a. [a] -> Number -> a
991990
992991## Module Control.Monad.Eff
993992
994−
995−
996993#### `Eff`
997994
998995``` purescript
@@ -1094,8 +1091,6 @@ foreachE :: forall e a. [a] -> (a -> Eff e Unit) -> Eff e Unit
10941091
10951092## Module Control.Monad.Eff.Unsafe
10961093
1097−
1098−
10991094#### `unsafeInterleaveEff`
11001095
11011096``` purescript
@@ -1106,8 +1101,6 @@ unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
11061101
11071102## Module Debug.Trace
11081103
1109−
1110−
11111104#### `Trace`
11121105
11131106``` purescript
@@ -1132,8 +1125,6 @@ print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
11321125
11331126## Module Control.Monad.ST
11341127
1135−
1136−
11371128#### `ST`
11381129
11391130``` purescript
prelude/prelude.purs+44−40
@@ -77,8 +77,7 @@ module Prelude
7777 -- |
7878 -- | `Semigroupoid`s should obey the following rule:
7979 -- |
80− -- | Association:
81− -- | `forall p q r. p <<< (q <<< r) = (p <<< q) <<< r`
80+ -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
8281 -- |
8382 class Semigroupoid a where
8483 (<<<) :: forall b c d. a c d -> a b c -> a b d
@@ -94,11 +93,8 @@ module Prelude
9493 -- |
9594 -- | `Category`s should obey the following rules.
9695 -- |
97− -- | Left Identity:
98− -- | `forall p. id <<< p = p`
99− -- |
100− -- | Right Identity:
101− -- | `forall p. p <<< id = p`
96+ -- | - Left Identity: `id <<< p = p`
97+ -- | - Right Identity: `p <<< id = p`
10298 -- |
10399 class (Semigroupoid a) <= Category a where
104100 id :: forall t. a t t
@@ -219,11 +215,8 @@ module Prelude
219215 -- |
220216 -- | `Functor`s should obey the following rules.
221217 -- |
222− -- | Identity:
223− -- | `(<$>) id = id`
224− -- |
225− -- | Composition:
226− -- | `forall f g. (<$>) (f . g) = ((<$>) f) . ((<$>) g)`
218+ -- | - Identity: `(<$>) id = id`
219+ -- | - Composition: `(<$>) (f <<< g) = (<$> f) <<< (<$> g)`
227220 -- |
228221 class Functor f where
229222 (<$>) :: forall a b. (a -> b) -> f a -> f b
@@ -239,10 +232,9 @@ module Prelude
239232 -- | `Apply`s are intuitively [`Applicative`](#applicative)s less `pure`, and more formally a
240233 -- | strong lax semi-monoidal endofunctor.
241234 -- |
242− -- | `Apply`s should obey the following rules.
235+ -- | `Apply`s should obey the following rule.
243236 -- |
244− -- | Associative Composition:
245− -- | `forall f g h. (.) <$> f <*> g <*> h = f <*> (g <*> h)`
237+ -- | - Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
246238 -- |
247239 class (Functor f) <= Apply f where
248240 (<*>) :: forall a b. f (a -> b) -> f a -> f b
@@ -252,17 +244,10 @@ module Prelude
252244 -- |
253245 -- | `Applicative`s should obey the following rules.
254246 -- |
255− -- | Identity:
256− -- | `forall v. (pure id) <*> v = v`
257− -- |
258− -- | Composition:
259− -- | `forall f g h. (pure (.)) <*> f <*> g <*> h = f <*> (g <*> h)`
260− -- |
261− -- | Homomorphism:
262− -- | `forall f x. (pure f) <*> (pure x) = pure (f x)`
263− -- |
264− -- | Interchange:
265− -- | `forall u y. u <*> (pure y) = (pure (($) y)) <*> u`
247+ -- | - Identity: `(pure id) <*> v = v`
248+ -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
249+ -- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
250+ -- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
266251 -- |
267252 class (Apply f) <= Applicative f where
268253 pure :: forall a. a -> f a
@@ -276,8 +261,7 @@ module Prelude
276261 -- |
277262 -- | `Bind`s should obey the following rule.
278263 -- |
279− -- | Associativity:
280− -- | `forall f g x. (x >>= f) >>= g = x >>= (\k => f k >>= g)`
264+ -- | - Associativity: `forall f g x. (x >>= f) >>= g = x >>= (\k => f k >>= g)`
281265 -- |
282266 class (Apply m) <= Bind m where
283267 (>>=) :: forall a b. m a -> (a -> m b) -> m b
@@ -287,11 +271,8 @@ module Prelude
287271 -- |
288272 -- | `Monad`s should obey the following rules.
289273 -- |
290− -- | Left Identity:
291− -- | `forall f x. pure x >>= f = f x`
292− -- |
293− -- | Right Identity:
294− -- | `forall x. x >>= pure = x`
274+ -- | - Left Identity: `pure x >>= f = f x`
275+ -- | - Right Identity: `x >>= pure = x`
295276 -- |
296277 class (Applicative m, Bind m) <= Monad m
297278
@@ -330,28 +311,43 @@ module Prelude
330311 infixl 6 -
331312 infixl 6 +
332313
333− -- | Addition and multiplication
314+ -- | Addition and multiplication, satisfying the following laws:
315+ -- |
316+ -- | - `a` is a commutative monoid under addition
317+ -- | - `a` is a monoid under multiplication
318+ -- | - multiplication distributes over addition
319+ -- | - multiplication by `zero` annihilates `a`
320+ -- |
334321 class Semiring a where
335322 (+) :: a -> a -> a
336323 zero :: a
337324 (*) :: a -> a -> a
338325 one :: a
339326
340− -- | Semiring with modulo operation and division where
341− -- | ```a / b * b + (a `mod` b) = a```
327+ -- | Addition, multiplication, modulo operation and division, satisfying:
328+ -- |
329+ -- | - ```a / b * b + (a `mod` b) = a```
330+ -- |
342331 class (Semiring a) <= ModuloSemiring a where
343332 (/) :: a -> a -> a
344333 mod :: a -> a -> a
345334
346− -- | Addition, multiplication, and subtraction
335+ -- | Addition, multiplication, and subtraction.
336+ -- |
337+ -- | Has the same laws as `Semiring` but additionally satisfying:
338+ -- |
339+ -- | - `a` is an abelian group under addition
340+ -- |
347341 class (Semiring a) <= Ring a where
348342 (-) :: a -> a -> a
349343
350344 negate :: forall a. (Ring a) => a -> a
351345 negate a = zero - a
352346
353− -- | Ring where every nonzero element has a multiplicative inverse (possibly
354− -- | a non-commutative field) so that ```a `mod` b = zero```
347+ -- | Ring where every nonzero element has a multiplicative inverse so that:
348+ -- |
349+ -- | - ```a `mod` b = zero```
350+ -- |
355351 class (Ring a, ModuloSemiring a) <= DivisionRing a
356352
357353 -- | A commutative field
@@ -429,6 +425,7 @@ module Prelude
429425 infix 4 ==
430426 infix 4 /=
431427
428+ -- | Class for types that have an equality comparison.
432429 class Eq a where
433430 (==) :: a -> a -> Boolean
434431 (/=) :: a -> a -> Boolean
@@ -505,7 +502,14 @@ module Prelude
505502 (<>) GT _ = GT
506503 (<>) EQ y = y
507504
508−
505+ -- | Class for types that have ordered comparisons.
506+ -- |
507+ -- | Represents a partially ordered set satisfying the following laws:
508+ -- |
509+ -- | - Reflexivity: `a <= a`
510+ -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
511+ -- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
512+ -- |
509513 class (Eq a) <= Ord a where
510514 compare :: a -> a -> Ordering
511515