@@ -1,14 +1,13 @@
11module Prelude
22 ( Unit(..), unit
3− , otherwise
3+ , ($), (#)
44 , flip
55 , const
66 , asTypeOf
7+ , otherwise
8+ , (:), cons
79 , Semigroupoid, (<<<), (>>>)
810 , Category, id
9− , ($), (#)
10− , (:), cons
11− , Show, show
1211 , Functor, (<$>), (<#>), void
1312 , Apply, (<*>)
1413 , Applicative, pure, liftA1
@@ -18,7 +17,6 @@ module Prelude
1817 , Semiring, (+), zero, (*), one
1918 , ModuloSemiring, (/), mod
2019 , Ring, (-), negate
21− , (%)
2220 , Num
2321 , DivisionRing
2422 , Eq, (==), (/=)
@@ -29,11 +27,14 @@ module Prelude
2927 , ComplementedLattice, not
3028 , DistributiveLattice
3129 , BooleanAlgebra
30+ , Show, show
3231 ) where
3332
34− -- | The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
33+ -- | The `Unit` type has a single inhabitant, called `unit`. It represents
34+ -- | values with no computational content.
3535 -- |
36− -- | `Unit` is often used, wrapped in a monadic type constructor, as the return type of a computation where only
36+ -- | `Unit` is often used, wrapped in a monadic type constructor, as the
37+ -- | return type of a computation where only
3738 -- | the _effects_ are important.
3839 newtype Unit = Unit {}
3940
@@ -41,78 +42,6 @@ module Prelude
4142 unit :: Unit
4243 unit = Unit {}
4344
44− -- | An alias for `true`, which can be useful in guard clauses:
45− -- |
46− -- | ```purescript
47− -- | max x y | x >= y = x
48− -- | | otherwise = y
49− -- | ```
50− otherwise :: Boolean
51− otherwise = true
52−
53− -- | Flips the order of the arguments to a function of two arguments.
54− -- |
55− -- | ```purescript
56− -- | flip const 1 2 = const 2 1 = 2
57− -- | ```
58− flip :: forall a b c. (a -> b -> c) -> b -> a -> c
59− flip f b a = f a b
60−
61− -- | Returns its first argument and ignores its second.
62− -- |
63− -- | ```purescript
64− -- | const 1 "hello" = 1
65− -- | ```
66− const :: forall a b. a -> b -> a
67− const a _ = a
68−
69− -- | This function returns its first argument, and can be used to assert type equalities.
70− -- | This can be useful when types are otherwise ambiguous.
71− -- |
72− -- | ```purescript
73− -- | main = print $ [] `asTypeOf` [0]
74− -- | ```
75− -- |
76− -- | If instead, we had written `main = print []`, the type of the argument `[]` would have
77− -- | been ambiguous, resulting in a compile-time error.
78− asTypeOf :: forall a. a -> a -> a
79− asTypeOf x _ = x
80−
81− infixr 9 >>>
82− infixr 9 <<<
83−
84− -- | A `Semigroupoid` is similar to a [`Category`](#category) but does not require an identity
85− -- | element `id`, just composable morphisms.
86− -- |
87− -- | `Semigroupoid`s should obey the following rule:
88− -- |
89− -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
90− -- |
91− -- | One example of a `Semigroupoid` is the function type constructor `(->)`, with `(<<<)` defined
92− -- | as function composition.
93− class Semigroupoid a where
94− (<<<) :: forall b c d. a c d -> a b c -> a b d
95−
96− instance semigroupoidArr :: Semigroupoid (->) where
97− (<<<) f g x = f (g x)
98−
99− -- | Forwards composition, or `(<<<)` with its arguments reversed.
100− (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
101− (>>>) f g = g <<< f
102−
103− -- | `Category`s consist of objects and composable morphisms between them, and as such are
104− -- | [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids` must have an identity element.
105− -- |
106− -- | `Category`s should obey the following rules.
107− -- |
108− -- | - Left Identity: `id <<< p = p`
109− -- | - Right Identity: `p <<< id = p`
110− class (Semigroupoid a) <= Category a where
111− id :: forall t. a t t
112−
113− instance categoryArr :: Category (->) where
114− id x = x
115−
11645 infixr 0 $
11746 infixl 0 #
11847
@@ -122,14 +51,14 @@ module Prelude
12251 -- | length $ groupBy productCategory $ filter isInStock $ products
12352 -- | ```
12453 -- |
125− -- | is equivalent to
54+ -- | is equivalent to:
12655 -- |
12756 -- | ```purescript
12857 -- | length (groupBy productCategory (filter isInStock products))
12958 -- | ```
13059 -- |
131− -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
132− -- | `a $ b $ c $ d x` = `a $ (b $ (c $ (d $ x)))` = `a (b (c (d x)))`
60+ -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of
61+ -- | left: `a $ b $ c $ d x = a $ (b $ (c $ (d $ x))) = a (b (c (d x)))`
13362 ($) :: forall a b. (a -> b) -> a -> b
13463 ($) f x = f x
13564
@@ -139,24 +68,53 @@ module Prelude
13968 -- | products # filter isInStock # groupBy productCategory # length
14069 -- | ```
14170 -- |
142− -- | is equivalent to
71+ -- | is equivalent to:
14372 -- |
14473 -- | ```purescript
14574 -- | length (groupBy productCategory (filter isInStock products))
14675 -- | ```
14776 -- |
148− -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
149− -- | `x # a # b # c # d` = `(((x # a) # b) # c) # d` = `d (c (b (a x)))`
77+ -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of
78+ -- | right: `x # a # b # c # d = (((x # a) # b) # c) # d = d (c (b (a x)))`
15079 (#) :: forall a b. a -> (a -> b) -> b
15180 (#) x f = f x
15281
153− infixr 6 :
82+ -- | Flips the order of the arguments to a function of two arguments.
83+ -- |
84+ -- | ```purescript
85+ -- | flip const 1 2 = const 2 1 = 2
86+ -- | ```
87+ flip :: forall a b c. (a -> b -> c) -> b -> a -> c
88+ flip f b a = f a b
15489
155− -- | An infix alias for `cons`.
90+ -- | Returns its first argument and ignores its second.
15691 -- |
157− -- | Note, the running time of this function is `O(n)`.
158− (:) :: forall a. a -> [a] -> [a]
159− (:) = cons
92+ -- | ```purescript
93+ -- | const 1 "hello" = 1
94+ -- | ```
95+ const :: forall a b. a -> b -> a
96+ const a _ = a
97+
98+ -- | This function returns its first argument, and can be used to assert type
99+ -- | equalities. This can be useful when types are otherwise ambiguous.
100+ -- |
101+ -- | ```purescript
102+ -- | main = print $ [] `asTypeOf` [0]
103+ -- | ```
104+ -- |
105+ -- | If instead, we had written `main = print []`, the type of the argument
106+ -- | `[]` would have been ambiguous, resulting in a compile-time error.
107+ asTypeOf :: forall a. a -> a -> a
108+ asTypeOf x _ = x
109+
110+ -- | An alias for `true`, which can be useful in guard clauses:
111+ -- |
112+ -- | ```purescript
113+ -- | max x y | x >= y = x
114+ -- | | otherwise = y
115+ -- | ```
116+ otherwise :: Boolean
117+ otherwise = true
160118
161119 -- | Attaches an element to the front of an array, creating a new array.
162120 -- |
@@ -174,70 +132,61 @@ module Prelude
174132 }
175133 """ :: forall a. a -> [a] -> [a]
176134
177− -- | The `Show` type class represents those types which can be converted into a human-readable `String` representation.
178− -- |
179− -- | While not required, it is recommended that for any expression `x`, the string `show x` be executable PureScript code
180− -- | which evaluates to the same value as the expression `x`.
181− class Show a where
182− show :: a -> String
183−
184− instance showBoolean :: Show Boolean where
185− show true = "true"
186− show false = "false"
187−
188− instance showNumber :: Show Number where
189− show = showNumberImpl
135+ infixr 6 :
190136
191− instance showString :: Show String where
192− show = showStringImpl
137+ -- | An infix alias for `cons`.
138+ -- |
139+ -- | Note, the running time of this function is `O(n)`.
140+ (:) :: forall a. a -> [a] -> [a]
141+ (:) = cons
193142
194− instance showUnit :: Show Unit where
195− show _ = "unit"
143+ infixr 9 >>>
144+ infixr 9 <<<
196145
197− instance showArray :: (Show a) => Show [a] where
198− show = showArrayImpl show
146+ -- | A `Semigroupoid` is similar to a [`Category`](#category) but does not
147+ -- | require an identity element `id`, just composable morphisms.
148+ -- |
149+ -- | `Semigroupoid`s must satisfy the following law:
150+ -- |
151+ -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
152+ -- |
153+ -- | One example of a `Semigroupoid` is the function type constructor `(->)`,
154+ -- | with `(<<<)` defined as function composition.
155+ class Semigroupoid a where
156+ (<<<) :: forall b c d. a c d -> a b c -> a b d
199157
200− instance showOrdering :: Show Ordering where
201− show LT = "LT"
202− show GT = "GT"
203− show EQ = "EQ"
158+ instance semigroupoidArr :: Semigroupoid (->) where
159+ (<<<) f g x = f (g x)
204160
205− foreign import showNumberImpl
206− """
207− function showNumberImpl(n) {
208− return n.toString();
209− }
210− """ :: Number -> String
161+ -- | Forwards composition, or `(<<<)` with its arguments reversed.
162+ (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
163+ (>>>) f g = g <<< f
211164
212− foreign import showStringImpl
213− """
214− function showStringImpl(s) {
215− return JSON.stringify(s);
216− }
217− """ :: String -> String
165+ -- | `Category`s consist of objects and composable morphisms between them, and
166+ -- | as such are [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids`
167+ -- | must have an identity element.
168+ -- |
169+ -- | Instances must satisfy the following law in addition to the
170+ -- | `Semigroupoid` law:
171+ -- |
172+ -- | - Identity: `id <<< p = p <<< id = p`
173+ class (Semigroupoid a) <= Category a where
174+ id :: forall t. a t t
218175
219− foreign import showArrayImpl
220− """
221− function showArrayImpl(f) {
222− return function(xs) {
223− var ss = [];
224− for (var i = 0, l = xs.length; i < l; i++) {
225− ss[i] = f(xs[i]);
226− }
227− return '[' + ss.join(',') + ']';
228− };
229− }
230− """ :: forall a. (a -> String) -> [a] -> String
176+ instance categoryArr :: Category (->) where
177+ id x = x
231178
232179 infixl 4 <$>
233180 infixl 1 <#>
234181
235− -- | A `Functor` is a type constructor which supports a mapping operation `(<$>)`.
182+ -- | A `Functor` is a type constructor which supports a mapping operation
183+ -- | `(<$>)`.
236184 -- |
237− -- | `(<$>)` can be used to turn functions `a -> b` into functions `f a -> f b` whose argument and return
238− -- | types use the type constructor `f` to represent some computational context.
185+ -- | `(<$>)` can be used to turn functions `a -> b` into functions
186+ -- | `f a -> f b` whose argument and return types use the type constructor `f`
187+ -- | to represent some computational context.
239188 -- |
240− -- | `Functor` instances should satisfy the following laws:
189+ -- | Instances must satisfy the following laws:
241190 -- |
242191 -- | - Identity: `(<$>) id = id`
243192 -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
@@ -255,10 +204,12 @@ module Prelude
255204 (<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
256205 (<#>) fa f = f <$> fa
257206
258− -- | The `void` function is used to ignore the type wrapped by a [`Functor`](#functor), replacing it with `Unit` and
259− -- | keeping only the type information provided by the type constructor itself.
207+ -- | The `void` function is used to ignore the type wrapped by a
208+ -- | [`Functor`](#functor), replacing it with `Unit` and keeping only the type
209+ -- | information provided by the type constructor itself.
260210 -- |
261− -- | `void` is often useful when using `do` notation to change the return type of a monadic computation:
211+ -- | `void` is often useful when using `do` notation to change the return type
212+ -- | of a monadic computation:
262213 -- |
263214 -- | ```purescript
264215 -- | main = forE 1 10 \n -> void do
@@ -270,22 +221,26 @@ module Prelude
270221
271222 infixl 4 <*>
272223
273− -- | The `Apply` class provides the `(<*>)` which is used to apply a function to an argument under a type constructor.
224+ -- | The `Apply` class provides the `(<*>)` which is used to apply a function
225+ -- | to an argument under a type constructor.
274226 -- |
275− -- | `Apply` can be used to lift functions of two or more arguments to work on values wrapped with the type constructor `f`.
276− -- | It might also be understood in terms of the `lift2` function:
227+ -- | `Apply` can be used to lift functions of two or more arguments to work on
228+ -- | values wrapped with the type constructor `f`. It might also be understood
229+ -- | in terms of the `lift2` function:
277230 -- |
278231 -- | ```purescript
279232 -- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
280233 -- | lift2 f a b = f <$> a <*> b
281234 -- | ```
282235 -- |
283− -- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts the function application operator `($)` to arguments
284− -- | wrapped with the type constructor `f`.
236+ -- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts
237+ -- | the function application operator `($)` to arguments wrapped with the
238+ -- | type constructor `f`.
285239 -- |
286− -- | `Apply` instances should satisfy the following law:
240+ -- | Instances must satisfy the following law in addition to the `Functor`
241+ -- | laws:
287242 -- |
288− -- | - Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
243+ -- | - Associative composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
289244 -- |
290245 -- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
291246 class (Functor f) <= Apply f where
@@ -294,14 +249,19 @@ module Prelude
294249 instance applyArr :: Apply ((->) r) where
295250 (<*>) f g x = f x (g x)
296251
297− -- | The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
298− -- | create values of type `f a` from values of type `a`.
252+ -- | The `Applicative` type class extends the [`Apply`](#apply) type class
253+ -- | with a `pure` function, which can be used to create values of type `f a`
254+ -- | from values of type `a`.
299255 -- |
300− -- | Where [`Apply`](#apply) provides the ability to lift functions of two or more arguments to functions whose arguments are wrapped using `f`,
301− -- | and [`Functor`](#functor) provides the ability to lift functions of one argument, `pure` can be seen as the function which lifts functions of
302− -- | _zero_ arguments. That is, `Applicative` functors support a lifting operation for any number of function arguments.
256+ -- | Where [`Apply`](#apply) provides the ability to lift functions of two or
257+ -- | more arguments to functions whose arguments are wrapped using `f`, and
258+ -- | [`Functor`](#functor) provides the ability to lift functions of one
259+ -- | argument, `pure` can be seen as the function which lifts functions of
260+ -- | _zero_ arguments. That is, `Applicative` functors support a lifting
261+ -- | operation for any number of function arguments.
303262 -- |
304− -- | `Applicative` instances should satisfy the following laws:
263+ -- | Instances must satisfy the following laws in addition to the `Apply`
264+ -- | laws:
305265 -- |
306266 -- | - Identity: `(pure id) <*> v = v`
307267 -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
@@ -317,10 +277,13 @@ module Prelude
317277 return :: forall m a. (Applicative m) => a -> m a
318278 return = pure
319279
320− -- | `liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
321− -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
280+ -- | `liftA1` provides a default implementation of `(<$>)` for any
281+ -- | [`Applicative`](#applicative) functor, without using `(<$>)` as provided
282+ -- | by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass
283+ -- | relationship.
322284 -- |
323− -- | `liftA1` can therefore be used to write [`Functor`](#functor) instances as follows:
285+ -- | `liftA1` can therefore be used to write [`Functor`](#functor) instances
286+ -- | as follows:
324287 -- |
325288 -- | ```purescript
326289 -- | instance functorF :: Functor F where
@@ -331,8 +294,9 @@ module Prelude
331294
332295 infixl 1 >>=
333296
334− -- | The `Bind` type class extends the [`Apply`](#apply) type class with a "bind" operation `(>>=)` which composes computations
335− -- | in sequence, using the return value of one computation to determine the next computation.
297+ -- | The `Bind` type class extends the [`Apply`](#apply) type class with a
298+ -- | "bind" operation `(>>=)` which composes computations in sequence, using
299+ -- | the return value of one computation to determine the next computation.
336300 -- |
337301 -- | The `>>=` operator can also be expressed using `do` notation, as follows:
338302 -- |
@@ -343,15 +307,13 @@ module Prelude
343307 -- |
344308 -- | where the function argument of `f` is given the name `y`.
345309 -- |
346− -- | `Bind` instances should satisfy the following law:
310+ -- | Instances must satisfy the following law in addition to the `Apply`
311+ -- | laws:
347312 -- |
348313 -- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
349314 -- |
350− -- | Or, expressed using `do` notation:
351− -- |
352− -- | - Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
353− -- |
354− -- | Associativity tells us that we can regroup operations which use do-notation, so that we can unambiguously write, for example:
315+ -- | Associativity tells us that we can regroup operations which use `do`
316+ -- | notation so that we can unambiguously write, for example:
355317 -- |
356318 -- | ```purescript
357319 -- | do x <- m1
@@ -364,26 +326,26 @@ module Prelude
364326 instance bindArr :: Bind ((->) r) where
365327 (>>=) m f x = f (m x) x
366328
367− -- | The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
368− -- | represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
329+ -- | The `Monad` type class combines the operations of the `Bind` and
330+ -- | `Applicative` type classes. Therefore, `Monad` instances represent type
331+ -- | constructors which support sequential composition, and also lifting of
332+ -- | functions of arbitrary arity.
369333 -- |
370− -- | `Monad` instances should satisfy the following laws:
334+ -- | Instances must satisfy the following laws in addition to the
335+ -- | `Applicative` and `Bind` laws:
371336 -- |
372337 -- | - Left Identity: `pure x >>= f = f x`
373338 -- | - Right Identity: `x >>= pure = x`
374− -- |
375− -- | Or, expressed using `do` notation:
376− -- |
377− -- | - Left Identity: `do { y <- pure x ; f y } = f x`
378− -- | - Right Identity: `do { y <- x ; pure y } = x`
379339 class (Applicative m, Bind m) <= Monad m
380340
381341 instance monadArr :: Monad ((->) r)
382342
383− -- | `liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
384− -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
343+ -- | `liftM1` provides a default implementation of `(<$>)` for any
344+ -- | [`Monad`](#monad), without using `(<$>)` as provided by the
345+ -- | [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
385346 -- |
386− -- | `liftM1` can therefore be used to write [`Functor`](#functor) instances as follows:
347+ -- | `liftM1` can therefore be used to write [`Functor`](#functor) instances
348+ -- | as follows:
387349 -- |
388350 -- | ```purescript
389351 -- | instance functorF :: Functor F where
@@ -394,10 +356,12 @@ module Prelude
394356 a' <- a
395357 return (f a')
396358
397− -- | `ap` provides a default implementation of `(<*>)` for any [`Monad`](#monad),
398− -- | without using `(<*>)` as provided by the [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
359+ -- | `ap` provides a default implementation of `(<*>)` for any
360+ -- | [`Monad`](#monad), without using `(<*>)` as provided by the
361+ -- | [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
399362 -- |
400− -- | `ap` can therefore be used to write [`Apply`](#apply) instances as follows:
363+ -- | `ap` can therefore be used to write [`Apply`](#apply) instances as
364+ -- | follows:
401365 -- |
402366 -- | ```purescript
403367 -- | instance applyF :: Apply F where
@@ -414,11 +378,12 @@ module Prelude
414378
415379 -- | The `Semigroup` type class identifies an associative operation on a type.
416380 -- |
417− -- | `Semigroup` instances are required to satisfy the following law:
381+ -- | Instances are required to satisfy the following law:
418382 -- |
419383 -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
420384 -- |
421− -- | For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
385+ -- | One example of a `Semigroup` is `String`, with `(<>)` defined as string
386+ -- | concatenation.
422387 class Semigroup a where
423388 (<>) :: a -> a -> a
424389
@@ -452,12 +417,22 @@ module Prelude
452417 infixl 6 +
453418 infixl 7 *
454419
455− -- | Addition and multiplication, satisfying the following laws:
456− -- |
457− -- | - `a` is a commutative monoid under addition
458− -- | - `a` is a monoid under multiplication
459− -- | - multiplication distributes over addition
460− -- | - multiplication by `zero` annihilates `a`
420+ -- | The `Semiring` class is for types that support an addition and
421+ -- | multiplication operation.
422+ -- |
423+ -- | Instances must satisfy the following laws:
424+ -- |
425+ -- | - Commutative monoid under addition:
426+ -- | - Associativity: `(a + b) + c = a + (b + c)`
427+ -- | - Identity: `zero + a = a + zero = a`
428+ -- | - Commutative: `a + b = b + a`
429+ -- | - Monoid under multiplication:
430+ -- | - Associativity: `(a * b) * c = a * (b * c)`
431+ -- | - Identity: `one * a = a * one = a`
432+ -- | - Multiplication distributes over addition:
433+ -- | - Left distributivity: `a * (b + c) = (a * b) + (a * c)`
434+ -- | - Right distributivity: `(a + b) * c = (a * c) + (b * c)`
435+ -- | - Annihiliation: `zero * a = a * zero = zero`
461436 class Semiring a where
462437 (+) :: a -> a -> a
463438 zero :: a
@@ -476,11 +451,36 @@ module Prelude
476451 (*) _ _ = unit
477452 one = unit
478453
454+ infixl 6 -
455+
456+ -- | The `Ring` class is for types that support addition, multiplication,
457+ -- | and subtraction operations.
458+ -- |
459+ -- | Instances must satisfy the following law in addition to the `Semiring`
460+ -- | laws:
461+ -- |
462+ -- | - Additive inverse: `a + (-a) = (-a) + a = zero`
463+ class (Semiring a) <= Ring a where
464+ (-) :: a -> a -> a
465+
466+ instance ringNumber :: Ring Number where
467+ (-) = numSub
468+
469+ instance ringUnit :: Ring Unit where
470+ (-) _ _ = unit
471+
472+ negate :: forall a. (Ring a) => a -> a
473+ negate a = zero - a
474+
479475 infixl 7 /
480476
481− -- | Addition, multiplication, modulo operation and division, satisfying:
477+ -- | The `ModuloSemiring` class is for types that support addition,
478+ -- | multiplication, division, and modulo (division remainder) operations.
479+ -- |
480+ -- | Instances must satisfy the following law in addition to the `Semiring`
481+ -- | laws:
482482 -- |
483− -- | - ```a / b * b + (a `mod` b) = a```
483+ -- | - Remainder: `a / b * b + (a `mod` b) = a`
484484 class (Semiring a) <= ModuloSemiring a where
485485 (/) :: a -> a -> a
486486 mod :: a -> a -> a
@@ -493,44 +493,33 @@ module Prelude
493493 (/) _ _ = unit
494494 mod _ _ = unit
495495
496− infixl 6 -
497−
498− -- | Addition, multiplication, and subtraction.
496+ -- | A `Ring` where every nonzero element has a multiplicative inverse.
499497 -- |
500− -- | Has the same laws as `Semiring` but additionally satisfying:
498+ -- | Instances must satisfy the following law in addition to the `Ring` and
499+ -- | `ModuloSemiring` laws:
501500 -- |
502− -- | - `a` is an abelian group under addition
503− class (Semiring a) <= Ring a where
504− (-) :: a -> a -> a
505−
506− instance ringNumber :: Ring Number where
507− (-) = numSub
508−
509− instance ringUnit :: Ring Unit where
510− (-) _ _ = unit
511−
512− negate :: forall a. (Ring a) => a -> a
513− negate a = zero - a
514−
515− -- | Ring where every nonzero element has a multiplicative inverse so that:
501+ -- | - Multiplicative inverse: `(one / x) * x = one`
516502 -- |
517− -- | - ```a `mod` b = zero```
503+ -- | As a consequence of this ```a `mod` b = zero``` as no divide operation
504+ -- | will have a remainder.
518505 class (Ring a, ModuloSemiring a) <= DivisionRing a
519506
520507 instance divisionRingNumber :: DivisionRing Number
521508
522509 instance divisionRingUnit :: DivisionRing Unit
523510
524− -- | A commutative field
511+ -- | The `Num` class is for types that are commutative fields.
512+ -- |
513+ -- | Instances must satisfy the following law in addition to the
514+ -- | `DivisionRing` laws:
515+ -- |
516+ -- | - Commutative multiplication: `a * b = b * a`
525517 class (DivisionRing a) <= Num a
526518
527519 instance numNumber :: Num Number
528520
529521 instance numUnit :: Num Unit
530522
531− infixl 7 %
532− (%) = numMod
533−
534523 foreign import numAdd
535524 """
536525 function numAdd(n1) {
@@ -567,15 +556,6 @@ module Prelude
567556 }
568557 """ :: Number -> Number -> Number
569558
570− foreign import numMod
571− """
572− function numMod(n1) {
573− return function(n2) {
574− return n1 % n2;
575− };
576− }
577− """ :: Number -> Number -> Number
578−
579559 infix 4 ==
580560 infix 4 /=
581561
@@ -646,7 +626,8 @@ module Prelude
646626 }
647627 """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
648628
649− -- | The `Ordering` data type represents the three possible outcomes of comparing two values:
629+ -- | The `Ordering` data type represents the three possible outcomes of
630+ -- | comparing two values:
650631 -- |
651632 -- | `LT` - The first value is _less than_ the second.
652633 -- | `GT` - The first value is _greater than_ the second.
@@ -873,6 +854,63 @@ module Prelude
873854 }
874855 """ :: Boolean -> Boolean
875856
857+ -- | The `Show` type class represents those types which can be converted into
858+ -- | a human-readable `String` representation.
859+ -- |
860+ -- | While not required, it is recommended that for any expression `x`, the
861+ -- | string `show x` be executable PureScript code which evaluates to the same
862+ -- | value as the expression `x`.
863+ class Show a where
864+ show :: a -> String
865+
866+ instance showBoolean :: Show Boolean where
867+ show true = "true"
868+ show false = "false"
869+
870+ instance showNumber :: Show Number where
871+ show = showNumberImpl
872+
873+ instance showString :: Show String where
874+ show = showStringImpl
875+
876+ instance showUnit :: Show Unit where
877+ show _ = "unit"
878+
879+ instance showArray :: (Show a) => Show [a] where
880+ show = showArrayImpl show
881+
882+ instance showOrdering :: Show Ordering where
883+ show LT = "LT"
884+ show GT = "GT"
885+ show EQ = "EQ"
886+
887+ foreign import showNumberImpl
888+ """
889+ function showNumberImpl(n) {
890+ return n.toString();
891+ }
892+ """ :: Number -> String
893+
894+ foreign import showStringImpl
895+ """
896+ function showStringImpl(s) {
897+ return JSON.stringify(s);
898+ }
899+ """ :: String -> String
900+
901+ foreign import showArrayImpl
902+ """
903+ function showArrayImpl(f) {
904+ return function(xs) {
905+ var ss = [];
906+ for (var i = 0, l = xs.length; i < l; i++) {
907+ ss[i] = f(xs[i]);
908+ }
909+ return '[' + ss.join(',') + ']';
910+ };
911+ }
912+ """ :: forall a. (a -> String) -> [a] -> String
913+
876914module Data.Function where
877915
878916 -- | The `on` function is used to change the domain of a binary operator.