@@ -1,14 +1,13 @@
1module Prelude
1module Prelude
2 ( Unit(..), unit
2 ( Unit(..), unit
3− , otherwise
3+ , ($), (#)
7 , Semigroupoid, (<<<), (>>>)
9 , Semigroupoid, (<<<), (>>>)
8 , Category, id
10 , Category, id
12 , Functor, (<$>), (<#>), void
11 , Functor, (<$>), (<#>), void
13 , Apply, (<*>)
12 , Apply, (<*>)
14 , Applicative, pure, liftA1
13 , Applicative, pure, liftA1
@@ -18,7 +17,6 @@ module Prelude
18 , Semiring, (+), zero, (*), one
17 , Semiring, (+), zero, (*), one
19 , ModuloSemiring, (/), mod
18 , ModuloSemiring, (/), mod
20 , Ring, (-), negate
19 , Ring, (-), negate
23 , DivisionRing
21 , DivisionRing
24 , Eq, (==), (/=)
22 , Eq, (==), (/=)
@@ -29,11 +27,14 @@ module Prelude
29 , ComplementedLattice, not
27 , ComplementedLattice, not
30 , DistributiveLattice
28 , DistributiveLattice
31 , BooleanAlgebra
29 , BooleanAlgebra
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.
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
37 -- | the _effects_ are important.
38 -- | the _effects_ are important.
38 newtype Unit = Unit {}
39 newtype Unit = Unit {}
@@ -41,78 +42,6 @@ module Prelude
41 unit :: Unit
42 unit :: Unit
42 unit = Unit {}
43 unit = Unit {}
44− -- | An alias for `true`, which can be useful in guard clauses:
47− -- | max x y | x >= y = x
53− -- | Flips the order of the arguments to a function of two arguments.
56− -- | flip const 1 2 = const 2 1 = 2
58− flip :: forall a b c. (a -> b -> c) -> b -> a -> c
61− -- | Returns its first argument and ignores its second.
64− -- | const 1 "hello" = 1
66− const :: forall a b. a -> b -> a
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.
73− -- | main = print $ [] `asTypeOf` [0]
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
84− -- | A `Semigroupoid` is similar to a [`Category`](#category) but does not require an identity
85− -- | element `id`, just composable morphisms.
87− -- | `Semigroupoid`s should obey the following rule:
89− -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
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
96− instance semigroupoidArr :: Semigroupoid (->) where
97− (<<<) f g x = f (g x)
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
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.
106− -- | `Category`s should obey the following rules.
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
113− instance categoryArr :: Category (->) where
116 infixr 0 $
45 infixr 0 $
117 infixl 0 #
46 infixl 0 #
@@ -122,14 +51,14 @@ module Prelude
122 -- | length $ groupBy productCategory $ filter isInStock $ products
51 -- | length $ groupBy productCategory $ filter isInStock $ products
125− -- | is equivalent to
54+ -- | is equivalent to:
127 -- | ```purescript
56 -- | ```purescript
128 -- | length (groupBy productCategory (filter isInStock products))
57 -- | length (groupBy productCategory (filter isInStock products))
131− -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
60+ -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of
132− -- | `a $ b $ c $ d x` = `a $ (b $ (c $ (d $ x)))` = `a (b (c (d x)))`
61+ -- | left: `a $ b $ c $ d x = a $ (b $ (c $ (d $ x))) = a (b (c (d x)))`
133 ($) :: forall a b. (a -> b) -> a -> b
62 ($) :: forall a b. (a -> b) -> a -> b
134 ($) f x = f x
63 ($) f x = f x
@@ -139,24 +68,53 @@ module Prelude
139 -- | products # filter isInStock # groupBy productCategory # length
68 -- | products # filter isInStock # groupBy productCategory # length
142− -- | is equivalent to
71+ -- | is equivalent to:
144 -- | ```purescript
73 -- | ```purescript
145 -- | length (groupBy productCategory (filter isInStock products))
74 -- | length (groupBy productCategory (filter isInStock products))
148− -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
77+ -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of
149− -- | `x # a # b # c # d` = `(((x # a) # b) # c) # d` = `d (c (b (a x)))`
78+ -- | right: `x # a # b # c # d = (((x # a) # b) # c) # d = d (c (b (a x)))`
150 (#) :: forall a b. a -> (a -> b) -> b
79 (#) :: forall a b. a -> (a -> b) -> b
151 (#) x f = f x
80 (#) x f = f x
153− infixr 6 :
82+ -- | Flips the order of the arguments to a function of two arguments.
85+ -- | flip const 1 2 = const 2 1 = 2
87+ flip :: forall a b c. (a -> b -> c) -> b -> a -> c
155− -- | An infix alias for `cons`.
90+ -- | Returns its first argument and ignores its second.
157− -- | Note, the running time of this function is `O(n)`.
92+ -- | ```purescript
93+ -- | const 1 "hello" = 1
95+ const :: forall a b. a -> b -> a
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.
102+ -- | main = print $ [] `asTypeOf` [0]
105+ -- | If instead, we had written `main = print []`, the type of the argument
106+ -- | `[]` would have been ambiguous, resulting in a compile-time error.
158− (:) :: forall a. a -> [a] -> [a]
107+ asTypeOf :: forall a. a -> a -> a
159− (:) = cons
108+ asTypeOf x _ = x
110+ -- | An alias for `true`, which can be useful in guard clauses:
113+ -- | max x y | x >= y = x
114+ -- | | otherwise = y
116+ otherwise :: Boolean
161 -- | Attaches an element to the front of an array, creating a new array.
119 -- | Attaches an element to the front of an array, creating a new array.
@@ -174,70 +132,61 @@ module Prelude
175 """ :: forall a. a -> [a] -> [a]
133 """ :: forall a. a -> [a] -> [a]
177− -- | The `Show` type class represents those types which can be converted into a human-readable `String` representation.
135+ infixr 6 :
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`.
184− instance showBoolean :: Show Boolean where
186− show false = "false"
188− instance showNumber :: Show Number where
189− show = showNumberImpl
191− instance showString :: Show String where
137+ -- | An infix alias for `cons`.
192− show = showStringImpl
138+ -- |
139+ -- | Note, the running time of this function is `O(n)`.
140+ (:) :: forall a. a -> [a] -> [a]
194− instance showUnit :: Show Unit where
143+ infixr 9 >>>
195− show _ = "unit"
144+ infixr 9 <<<
197− instance showArray :: (Show a) => Show [a] where
146+ -- | A `Semigroupoid` is similar to a [`Category`](#category) but does not
198− show = showArrayImpl show
147+ -- | require an identity element `id`, just composable morphisms.
149+ -- | `Semigroupoid`s must satisfy the following law:
151+ -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
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
200− instance showOrdering :: Show Ordering where
158+ instance semigroupoidArr :: Semigroupoid (->) where
201− show LT = "LT"
159+ (<<<) f g x = f (g x)
205− foreign import showNumberImpl
161+ -- | Forwards composition, or `(<<<)` with its arguments reversed.
206− """
162+ (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
207− function showNumberImpl(n) {
163+ (>>>) f g = g <<< f
208− return n.toString();
210− """ :: Number -> String
212− foreign import showStringImpl
165+ -- | `Category`s consist of objects and composable morphisms between them, and
213− """
166+ -- | as such are [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids`
214− function showStringImpl(s) {
167+ -- | must have an identity element.
215− return JSON.stringify(s);
168+ -- |
216− }
169+ -- | Instances must satisfy the following law in addition to the
217− """ :: String -> String
170+ -- | `Semigroupoid` law:
172+ -- | - Identity: `id <<< p = p <<< id = p`
173+ class (Semigroupoid a) <= Category a where
174+ id :: forall t. a t t
219− foreign import showArrayImpl
176+ instance categoryArr :: Category (->) where
221− function showArrayImpl(f) {
222− return function(xs) {
224− for (var i = 0, l = xs.length; i < l; i++) {
227− return '[' + ss.join(',') + ']';
230− """ :: forall a. (a -> String) -> [a] -> String
232 infixl 4 <$>
179 infixl 4 <$>
233 infixl 1 <#>
180 infixl 1 <#>
235− -- | A `Functor` is a type constructor which supports a mapping operation `(<$>)`.
182+ -- | A `Functor` is a type constructor which supports a mapping operation
237− -- | `(<$>)` can be used to turn functions `a -> b` into functions `f a -> f b` whose argument and return
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`
238− -- | types use the type constructor `f` to represent some computational context.
187+ -- | to represent some computational context.
240− -- | `Functor` instances should satisfy the following laws:
189+ -- | Instances must satisfy the following laws:
242 -- | - Identity: `(<$>) id = id`
191 -- | - Identity: `(<$>) id = id`
243 -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
192 -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
@@ -255,10 +204,12 @@ module Prelude
255 (<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
204 (<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
256 (<#>) fa f = f <$> fa
205 (<#>) fa f = f <$> fa
258− -- | The `void` function is used to ignore the type wrapped by a [`Functor`](#functor), replacing it with `Unit` and
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
259− -- | keeping only the type information provided by the type constructor itself.
209+ -- | information provided by the type constructor itself.
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:
263 -- | ```purescript
214 -- | ```purescript
264 -- | main = forE 1 10 \n -> void do
215 -- | main = forE 1 10 \n -> void do
@@ -270,22 +221,26 @@ module Prelude
271 infixl 4 <*>
222 infixl 4 <*>
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.
275− -- | `Apply` can be used to lift functions of two or more arguments to work on values wrapped with the type constructor `f`.
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
276− -- | It might also be understood in terms of the `lift2` function:
229+ -- | in terms of the `lift2` function:
278 -- | ```purescript
231 -- | ```purescript
279 -- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
232 -- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
280 -- | lift2 f a b = f <$> a <*> b
233 -- | lift2 f a b = f <$> a <*> b
283− -- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts the function application operator `($)` to arguments
236+ -- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts
237+ -- | the function application operator `($)` to arguments wrapped with the
284− -- | wrapped with the type constructor `f`.
238+ -- | type constructor `f`.
286− -- | `Apply` instances should satisfy the following law:
240+ -- | Instances must satisfy the following law in addition to the `Functor`
288− -- | - Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
243+ -- | - Associative composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
290 -- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
245 -- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
291 class (Functor f) <= Apply f where
246 class (Functor f) <= Apply f where
@@ -294,14 +249,19 @@ module Prelude
294 instance applyArr :: Apply ((->) r) where
249 instance applyArr :: Apply ((->) r) where
295 (<*>) f g x = f x (g x)
250 (<*>) f g x = f x (g x)
297− -- | The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
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`
298− -- | create values of type `f a` from values of type `a`.
254+ -- | from values of type `a`.
300− -- | Where [`Apply`](#apply) provides the ability to lift functions of two or more arguments to functions whose arguments are wrapped using `f`,
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
301− -- | and [`Functor`](#functor) provides the ability to lift functions of one argument, `pure` can be seen as the function which lifts functions of
259+ -- | 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.
260+ -- | _zero_ arguments. That is, `Applicative` functors support a lifting
261+ -- | operation for any number of function arguments.
304− -- | `Applicative` instances should satisfy the following laws:
263+ -- | Instances must satisfy the following laws in addition to the `Apply`
306 -- | - Identity: `(pure id) <*> v = v`
266 -- | - Identity: `(pure id) <*> v = v`
307 -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
267 -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
@@ -317,10 +277,13 @@ module Prelude
317 return :: forall m a. (Applicative m) => a -> m a
277 return :: forall m a. (Applicative m) => a -> m a
318 return = pure
278 return = pure
320− -- | `liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
280+ -- | `liftA1` provides a default implementation of `(<$>)` for any
281+ -- | [`Applicative`](#applicative) functor, without using `(<$>)` as provided
321− -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
282+ -- | by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass
323− -- | `liftA1` can therefore be used to write [`Functor`](#functor) instances as follows:
285+ -- | `liftA1` can therefore be used to write [`Functor`](#functor) instances
325 -- | ```purescript
288 -- | ```purescript
326 -- | instance functorF :: Functor F where
289 -- | instance functorF :: Functor F where
@@ -331,8 +294,9 @@ module Prelude
332 infixl 1 >>=
295 infixl 1 >>=
334− -- | The `Bind` type class extends the [`Apply`](#apply) type class with a "bind" operation `(>>=)` which composes computations
297+ -- | The `Bind` type class extends the [`Apply`](#apply) type class with a
298+ -- | "bind" operation `(>>=)` which composes computations in sequence, using
335− -- | in sequence, using the return value of one computation to determine the next computation.
299+ -- | the return value of one computation to determine the next computation.
337 -- | The `>>=` operator can also be expressed using `do` notation, as follows:
301 -- | The `>>=` operator can also be expressed using `do` notation, as follows:
@@ -343,15 +307,13 @@ module Prelude
344 -- | where the function argument of `f` is given the name `y`.
308 -- | where the function argument of `f` is given the name `y`.
346− -- | `Bind` instances should satisfy the following law:
310+ -- | Instances must satisfy the following law in addition to the `Apply`
348 -- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
313 -- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
350− -- | Or, expressed using `do` notation:
352− -- | - Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
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:
356 -- | ```purescript
318 -- | ```purescript
357 -- | do x <- m1
319 -- | do x <- m1
@@ -364,26 +326,26 @@ module Prelude
364 instance bindArr :: Bind ((->) r) where
326 instance bindArr :: Bind ((->) r) where
365 (>>=) m f x = f (m x) x
327 (>>=) m f x = f (m x) x
367− -- | The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
329+ -- | The `Monad` type class combines the operations of the `Bind` and
330+ -- | `Applicative` type classes. Therefore, `Monad` instances represent type
368− -- | represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
331+ -- | constructors which support sequential composition, and also lifting of
332+ -- | functions of arbitrary arity.
370− -- | `Monad` instances should satisfy the following laws:
334+ -- | Instances must satisfy the following laws in addition to the
335+ -- | `Applicative` and `Bind` laws:
372 -- | - Left Identity: `pure x >>= f = f x`
337 -- | - Left Identity: `pure x >>= f = f x`
373 -- | - Right Identity: `x >>= pure = x`
338 -- | - Right Identity: `x >>= pure = x`
375− -- | Or, expressed using `do` notation:
377− -- | - Left Identity: `do { y <- pure x ; f y } = f x`
378− -- | - Right Identity: `do { y <- x ; pure y } = x`
379 class (Applicative m, Bind m) <= Monad m
339 class (Applicative m, Bind m) <= Monad m
381 instance monadArr :: Monad ((->) r)
341 instance monadArr :: Monad ((->) r)
383− -- | `liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
343+ -- | `liftM1` provides a default implementation of `(<$>)` for any
344+ -- | [`Monad`](#monad), without using `(<$>)` as provided by the
384− -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
345+ -- | [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
386− -- | `liftM1` can therefore be used to write [`Functor`](#functor) instances as follows:
347+ -- | `liftM1` can therefore be used to write [`Functor`](#functor) instances
388 -- | ```purescript
350 -- | ```purescript
389 -- | instance functorF :: Functor F where
351 -- | instance functorF :: Functor F where
@@ -394,10 +356,12 @@ module Prelude
395 return (f a')
357 return (f a')
397− -- | `ap` provides a default implementation of `(<*>)` for any [`Monad`](#monad),
359+ -- | `ap` provides a default implementation of `(<*>)` for any
360+ -- | [`Monad`](#monad), without using `(<*>)` as provided by the
398− -- | without using `(<*>)` as provided by the [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
361+ -- | [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
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
402 -- | ```purescript
366 -- | ```purescript
403 -- | instance applyF :: Apply F where
367 -- | instance applyF :: Apply F where
@@ -414,11 +378,12 @@ module Prelude
415 -- | The `Semigroup` type class identifies an associative operation on a type.
379 -- | The `Semigroup` type class identifies an associative operation on a type.
417− -- | `Semigroup` instances are required to satisfy the following law:
381+ -- | Instances are required to satisfy the following law:
419 -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
383 -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
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
422 class Semigroup a where
387 class Semigroup a where
423 (<>) :: a -> a -> a
388 (<>) :: a -> a -> a
@@ -452,12 +417,22 @@ module Prelude
452 infixl 6 +
417 infixl 6 +
453 infixl 7 *
418 infixl 7 *
455− -- | Addition and multiplication, satisfying the following laws:
420+ -- | The `Semiring` class is for types that support an addition and
421+ -- | multiplication operation.
423+ -- | Instances must satisfy the following laws:
457− -- | - `a` is a commutative monoid under addition
425+ -- | - Commutative monoid under addition:
458− -- | - `a` is a monoid under multiplication
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`
459− -- | - multiplication distributes over addition
432+ -- | - Multiplication distributes over addition:
460− -- | - multiplication by `zero` annihilates `a`
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`
461 class Semiring a where
436 class Semiring a where
462 (+) :: a -> a -> a
437 (+) :: a -> a -> a
463 zero :: a
438 zero :: a
@@ -476,11 +451,36 @@ module Prelude
476 (*) _ _ = unit
451 (*) _ _ = unit
477 one = unit
452 one = unit
456+ -- | The `Ring` class is for types that support addition, multiplication,
457+ -- | and subtraction operations.
459+ -- | Instances must satisfy the following law in addition to the `Semiring`
462+ -- | - Additive inverse: `a + (-a) = (-a) + a = zero`
463+ class (Semiring a) <= Ring a where
466+ instance ringNumber :: Ring Number where
469+ instance ringUnit :: Ring Unit where
472+ negate :: forall a. (Ring a) => a -> a
479 infixl 7 /
475 infixl 7 /
477+ -- | The `ModuloSemiring` class is for types that support addition,
481− -- | Addition, multiplication, modulo operation and division, satisfying:
478+ -- | multiplication, division, and modulo (division remainder) operations.
480+ -- | Instances must satisfy the following law in addition to the `Semiring`
483− -- | - ```a / b * b + (a `mod` b) = a```
483+ -- | - Remainder: `a / b * b + (a `mod` b) = a`
484 class (Semiring a) <= ModuloSemiring a where
484 class (Semiring a) <= ModuloSemiring a where
485 (/) :: a -> a -> a
485 (/) :: a -> a -> a
486 mod :: a -> a -> a
486 mod :: a -> a -> a
@@ -493,44 +493,33 @@ module Prelude
493 (/) _ _ = unit
493 (/) _ _ = unit
494 mod _ _ = unit
494 mod _ _ = unit
496− infixl 6 -
496+ -- | A `Ring` where every nonzero element has a multiplicative inverse.
498− -- | Addition, multiplication, and subtraction.
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:
502− -- | - `a` is an abelian group under addition
501+ -- | - Multiplicative inverse: `(one / x) * x = one`
503− class (Semiring a) <= Ring a where
506− instance ringNumber :: Ring Number where
509− instance ringUnit :: Ring Unit where
512− negate :: forall a. (Ring a) => a -> a
515− -- | Ring where every nonzero element has a multiplicative inverse so that:
517− -- | - ```a `mod` b = zero```
503+ -- | As a consequence of this ```a `mod` b = zero``` as no divide operation
504+ -- | will have a remainder.
518 class (Ring a, ModuloSemiring a) <= DivisionRing a
505 class (Ring a, ModuloSemiring a) <= DivisionRing a
520 instance divisionRingNumber :: DivisionRing Number
507 instance divisionRingNumber :: DivisionRing Number
522 instance divisionRingUnit :: DivisionRing Unit
509 instance divisionRingUnit :: DivisionRing Unit
524− -- | A commutative field
511+ -- | The `Num` class is for types that are commutative fields.
513+ -- | Instances must satisfy the following law in addition to the
514+ -- | `DivisionRing` laws:
516+ -- | - Commutative multiplication: `a * b = b * a`
525 class (DivisionRing a) <= Num a
517 class (DivisionRing a) <= Num a
527 instance numNumber :: Num Number
519 instance numNumber :: Num Number
529 instance numUnit :: Num Unit
521 instance numUnit :: Num Unit
534 foreign import numAdd
523 foreign import numAdd
536 function numAdd(n1) {
525 function numAdd(n1) {
@@ -567,15 +556,6 @@ module Prelude
568 """ :: Number -> Number -> Number
557 """ :: Number -> Number -> Number
570− foreign import numMod
572− function numMod(n1) {
573− return function(n2) {
577− """ :: Number -> Number -> Number
579 infix 4 ==
559 infix 4 ==
580 infix 4 /=
560 infix 4 /=
@@ -646,7 +626,8 @@ module Prelude
647 """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
627 """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
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:
651 -- | `LT` - The first value is _less than_ the second.
632 -- | `LT` - The first value is _less than_ the second.
652 -- | `GT` - The first value is _greater than_ the second.
633 -- | `GT` - The first value is _greater than_ the second.
@@ -873,6 +854,63 @@ module Prelude
874 """ :: Boolean -> Boolean
855 """ :: Boolean -> Boolean
857+ -- | The `Show` type class represents those types which can be converted into
858+ -- | a human-readable `String` representation.
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`.
866+ instance showBoolean :: Show Boolean where
868+ show false = "false"
870+ instance showNumber :: Show Number where
871+ show = showNumberImpl
873+ instance showString :: Show String where
874+ show = showStringImpl
876+ instance showUnit :: Show Unit where
879+ instance showArray :: (Show a) => Show [a] where
880+ show = showArrayImpl show
882+ instance showOrdering :: Show Ordering where
887+ foreign import showNumberImpl
889+ function showNumberImpl(n) {
890+ return n.toString();
892+ """ :: Number -> String
894+ foreign import showStringImpl
896+ function showStringImpl(s) {
897+ return JSON.stringify(s);
899+ """ :: String -> String
901+ foreign import showArrayImpl
903+ function showArrayImpl(f) {
904+ return function(xs) {
906+ for (var i = 0, l = xs.length; i < l; i++) {
909+ return '[' + ss.join(',') + ']';
912+ """ :: forall a. (a -> String) -> [a] -> String
876module Data.Function where
914module Data.Function where
878 -- | The `on` function is used to change the domain of a binary operator.
916 -- | The `on` function is used to change the domain of a binary operator.