git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1016 from purescript/prelude
f0e9915Gary Burgess
prelude/README.md+202−174
@@ -2,6 +2,26 @@
2
2
3## Module Prelude
3## Module Prelude
4
4
5+#### `Unit`
6+
7+``` purescript
8+newtype Unit
9+ = Unit { }
10+```
11+
12+The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
13+
14+`Unit` is often used, wrapped in a monadic type constructor, as the return type of a computation where only
15+the _effects_ are important.
16+
17+#### `unit`
18+
19+``` purescript
20+unit :: Unit
21+```
22+
23+`unit` is the sole inhabitant of the `Unit` type.
24+
5#### `otherwise`
25#### `otherwise`
6
26
7``` purescript
27``` purescript
@@ -15,7 +35,6 @@ max x y | x >= y = x
15 | otherwise = y
35 | otherwise = y
16```
36```
17
37
18−
19#### `flip`
38#### `flip`
20
39
21``` purescript
40``` purescript
@@ -28,7 +47,6 @@ Flips the order of the arguments to a function of two arguments.
28flip const 1 2 = const 2 1 = 2
47flip const 1 2 = const 2 1 = 2
29```
48```
30
49
31−
32#### `const`
50#### `const`
33
51
34``` purescript
52``` purescript
@@ -41,7 +59,6 @@ Returns its first argument and ignores its second.
41const 1 "hello" = 1
59const 1 "hello" = 1
42```
60```
43
61
44−
45#### `asTypeOf`
62#### `asTypeOf`
46
63
47``` purescript
64``` purescript
@@ -105,7 +122,6 @@ class (Semigroupoid a) <= Category a where
105- Left Identity: `id <<< p = p`
122- Left Identity: `id <<< p = p`
106- Right Identity: `p <<< id = p`
123- Right Identity: `p <<< id = p`
107
124
108−
109#### `categoryArr`
125#### `categoryArr`
110
126
111``` purescript
127``` purescript
@@ -134,7 +150,6 @@ length (groupBy productCategory (filter isInStock products))
134`($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
150`($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
135`a $ b $ c $ d x` = `a $ (b $ (c $ (d $ x)))` = `a (b (c (d x)))`
151`a $ b $ c $ d x` = `a $ (b $ (c $ (d $ x)))` = `a (b (c (d x)))`
136
152
137−
138#### `(#)`
153#### `(#)`
139
154
140``` purescript
155``` purescript
@@ -156,7 +171,6 @@ length (groupBy productCategory (filter isInStock products))
156`(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
171`(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
157`x # a # b # c # d` = `(((x # a) # b) # c) # d` = `d (c (b (a x)))`
172`x # a # b # c # d` = `(((x # a) # b) # c) # d` = `d (c (b (a x)))`
158
173
159−
160#### `(:)`
174#### `(:)`
161
175
162``` purescript
176``` purescript
@@ -193,31 +207,31 @@ The `Show` type class represents those types which can be converted into a human
193While not required, it is recommended that for any expression `x`, the string `show x` be executable PureScript code
207While not required, it is recommended that for any expression `x`, the string `show x` be executable PureScript code
194which evaluates to the same value as the expression `x`.
208which evaluates to the same value as the expression `x`.
195
209
196−#### `showUnit`
210+#### `showBoolean`
197
211
198``` purescript
212``` purescript
199−instance showUnit :: Show Unit
213+instance showBoolean :: Show Boolean
200```
214```
201
215
202
216
203−#### `showString`
217+#### `showNumber`
204
218
205``` purescript
219``` purescript
206−instance showString :: Show String
220+instance showNumber :: Show Number
207```
221```
208
222
209
223
210−#### `showBoolean`
224+#### `showString`
211
225
212``` purescript
226``` purescript
213−instance showBoolean :: Show Boolean
227+instance showString :: Show String
214```
228```
215
229
216
230
217−#### `showNumber`
231+#### `showUnit`
218
232
219``` purescript
233``` purescript
220−instance showNumber :: Show Number
234+instance showUnit :: Show Unit
221```
235```
222
236
223
237
@@ -228,6 +242,13 @@ instance showArray :: (Show a) => Show [a]
228```
242```
229
243
230
244
245+#### `showOrdering`
246+
247+``` purescript
248+instance showOrdering :: Show Ordering
249+```
250+
251+
231#### `Functor`
252#### `Functor`
232
253
233``` purescript
254``` purescript
@@ -245,6 +266,12 @@ types use the type constructor `f` to represent some computational context.
245- Identity: `(<$>) id = id`
266- Identity: `(<$>) id = id`
246- Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
267- Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
247
268
269+#### `functorArr`
270+
271+``` purescript
272+instance functorArr :: Functor (Prim.Function r)
273+```
274+
248
275
249#### `(<#>)`
276#### `(<#>)`
250
277
@@ -301,6 +328,13 @@ wrapped with the type constructor `f`.
301
328
302Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
329Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
303
330
331+#### `applyArr`
332+
333+``` purescript
334+instance applyArr :: Apply (Prim.Function r)
335+```
336+
337+
304#### `Applicative`
338#### `Applicative`
305
339
306``` purescript
340``` purescript
@@ -322,6 +356,20 @@ _zero_ arguments. That is, `Applicative` functors support a lifting operation fo
322- Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
356- Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
323- Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
357- Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
324
358
359+#### `applicativeArr`
360+
361+``` purescript
362+instance applicativeArr :: Applicative (Prim.Function r)
363+```
364+
365+
366+#### `return`
367+
368+``` purescript
369+return :: forall m a. (Applicative m) => a -> m a
370+```
371+
372+`return` is an alias for `pure`.
325
373
326#### `liftA1`
374#### `liftA1`
327
375
@@ -374,6 +422,13 @@ do x <- m1
374 m3 x y
422 m3 x y
375```
423```
376
424
425+#### `bindArr`
426+
427+``` purescript
428+instance bindArr :: Bind (Prim.Function r)
429+```
430+
431+
377#### `Monad`
432#### `Monad`
378
433
379``` purescript
434``` purescript
@@ -393,14 +448,12 @@ Or, expressed using `do` notation:
393- Left Identity: `do { y <- pure x ; f y } = f x`
448- Left Identity: `do { y <- pure x ; f y } = f x`
394- Right Identity: `do { y <- x ; pure y } = x`
449- Right Identity: `do { y <- x ; pure y } = x`
395
450
396−
451+#### `monadArr`
397−#### `return`
398
452
399``` purescript
453``` purescript
400−return :: forall m a. (Monad m) => a -> m a
454+instance monadArr :: Monad (Prim.Function r)
401```
455```
402
456
403−`return` is an alias for `pure`.
404
457
405#### `liftM1`
458#### `liftM1`
406
459
@@ -434,38 +487,54 @@ instance applyF :: Apply F where
434 (<*>) = ap
487 (<*>) = ap
435```
488```
436
489
437−#### `functorArr`
490+#### `Semigroup`
438
491
439``` purescript
492``` purescript
440−instance functorArr :: Functor (Prim.Function r)
493+class Semigroup a where
494+ (<>) :: a -> a -> a
441```
495```
442
496
497+The `Semigroup` type class identifies an associative operation on a type.
443
498
499+`Semigroup` instances are required to satisfy the following law:
500+
501+- Associativity: `(x <> y) <> z = x <> (y <> z)`
502+
503+For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
504+
444−#### `applyArr`
505+#### `(++)`
445
506
446``` purescript
507``` purescript
447−instance applyArr :: Apply (Prim.Function r)
508+(++) :: forall s. (Semigroup s) => s -> s -> s
448```
509```
449
510
511+`(++)` is an alias for `(<>)`.
450
512
451−#### `applicativeArr`
513+#### `semigroupString`
452
514
453``` purescript
515``` purescript
454−instance applicativeArr :: Applicative (Prim.Function r)
516+instance semigroupString :: Semigroup String
455```
517```
456
518
457
519
458−#### `bindArr`
520+#### `semigroupUnit`
459
521
460``` purescript
522``` purescript
461−instance bindArr :: Bind (Prim.Function r)
523+instance semigroupUnit :: Semigroup Unit
462```
524```
463
525
464
526
465−#### `monadArr`
527+#### `semigroupArr`
466
528
467``` purescript
529``` purescript
468−instance monadArr :: Monad (Prim.Function r)
530+instance semigroupArr :: (Semigroup s') => Semigroup (s -> s')
531+```
532+
533+
534+#### `semigroupOrdering`
535+
536+``` purescript
537+instance semigroupOrdering :: Semigroup Ordering
469```
538```
470
539
471
540
@@ -486,6 +555,19 @@ Addition and multiplication, satisfying the following laws:
486- multiplication distributes over addition
555- multiplication distributes over addition
487- multiplication by `zero` annihilates `a`
556- multiplication by `zero` annihilates `a`
488
557
558+#### `semiringNumber`
559+
560+``` purescript
561+instance semiringNumber :: Semiring Number
562+```
563+
564+
565+#### `semiringUnit`
566+
567+``` purescript
568+instance semiringUnit :: Semiring Unit
569+```
570+
489
571
490#### `ModuloSemiring`
572#### `ModuloSemiring`
491
573
@@ -499,6 +581,19 @@ Addition, multiplication, modulo operation and division, satisfying:
499
581
500- ```a / b * b + (a `mod` b) = a```
582- ```a / b * b + (a `mod` b) = a```
501
583
584+#### `moduloSemiringNumber`
585+
586+``` purescript
587+instance moduloSemiringNumber :: ModuloSemiring Number
588+```
589+
590+
591+#### `moduloSemiringUnit`
592+
593+``` purescript
594+instance moduloSemiringUnit :: ModuloSemiring Unit
595+```
596+
502
597
503#### `Ring`
598#### `Ring`
504
599
@@ -513,60 +608,58 @@ Has the same laws as `Semiring` but additionally satisfying:
513
608
514- `a` is an abelian group under addition
609- `a` is an abelian group under addition
515
610
516−
611+#### `ringNumber`
517−#### `negate`
518
612
519``` purescript
613``` purescript
520−negate :: forall a. (Ring a) => a -> a
614+instance ringNumber :: Ring Number
521```
615```
522
616
523
617
524−#### `DivisionRing`
618+#### `ringUnit`
525
619
526``` purescript
620``` purescript
527−class (Ring a, ModuloSemiring a) <= DivisionRing a where
621+instance ringUnit :: Ring Unit
528```
622```
529
623
530−Ring where every nonzero element has a multiplicative inverse so that:
531
624
532−- ```a `mod` b = zero```
625+#### `negate`
533−
534−
535−#### `Num`
536
626
537``` purescript
627``` purescript
538−class (DivisionRing a) <= Num a where
628+negate :: forall a. (Ring a) => a -> a
539```
629```
540
630
541−A commutative field
542
631
543−#### `semiringNumber`
632+#### `DivisionRing`
544
633
545``` purescript
634``` purescript
546−instance semiringNumber :: Semiring Number
635+class (Ring a, ModuloSemiring a) <= DivisionRing a where
547```
636```
548
637
638+Ring where every nonzero element has a multiplicative inverse so that:
549
639
550−#### `ringNumber`
640+- ```a `mod` b = zero```
641+
642+#### `divisionRingNumber`
551
643
552``` purescript
644``` purescript
553−instance ringNumber :: Ring Number
645+instance divisionRingNumber :: DivisionRing Number
554```
646```
555
647
556
648
557−#### `moduloSemiringNumber`
649+#### `divisionRingUnit`
558
650
559``` purescript
651``` purescript
560−instance moduloSemiringNumber :: ModuloSemiring Number
652+instance divisionRingUnit :: DivisionRing Unit
561```
653```
562
654
563
655
564−#### `divisionRingNumber`
656+#### `Num`
565
657
566``` purescript
658``` purescript
567−instance divisionRingNumber :: DivisionRing Number
659+class (DivisionRing a) <= Num a where
568```
660```
569
661
662+A commutative field
570
663
571#### `numNumber`
664#### `numNumber`
572
665
@@ -575,25 +668,12 @@ instance numNumber :: Num Number
575```
668```
576
669
577
670
578−#### `Unit`
671+#### `numUnit`
579−
580−``` purescript
581−newtype Unit
582− = Unit { }
583−```
584−
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.
589−
590−#### `unit`
591
672
592``` purescript
673``` purescript
593−unit :: Unit
674+instance numUnit :: Num Unit
594```
675```
595
676
596−`unit` is the sole inhabitant of the `Unit` type.
597
677
598#### `Eq`
678#### `Eq`
599
679
@@ -614,31 +694,31 @@ The `Eq` type class represents types which support decidable equality.
614
694
615`(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
695`(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
616
696
617−#### `eqUnit`
697+#### `eqBoolean`
618
698
619``` purescript
699``` purescript
620−instance eqUnit :: Eq Unit
700+instance eqBoolean :: Eq Boolean
621```
701```
622
702
623
703
624−#### `eqString`
704+#### `eqNumber`
625
705
626``` purescript
706``` purescript
627−instance eqString :: Eq String
707+instance eqNumber :: Eq Number
628```
708```
629
709
630
710
631−#### `eqNumber`
711+#### `eqString`
632
712
633``` purescript
713``` purescript
634−instance eqNumber :: Eq Number
714+instance eqString :: Eq String
635```
715```
636
716
637
717
638−#### `eqBoolean`
718+#### `eqUnit`
639
719
640``` purescript
720``` purescript
641−instance eqBoolean :: Eq Boolean
721+instance eqUnit :: Eq Unit
642```
722```
643
723
644
724
@@ -664,27 +744,6 @@ The `Ordering` data type represents the three possible outcomes of comparing two
664`GT` - The first value is _greater than_ the second.
744`GT` - The first value is _greater than_ the second.
665`EQ` - The first value is _equal to_ or _incomparable to_ the second.
745`EQ` - The first value is _equal to_ or _incomparable to_ the second.
666
746
667−#### `eqOrdering`
668−
669−``` purescript
670−instance eqOrdering :: Eq Ordering
671−```
672−
673−
674−#### `showOrdering`
675−
676−``` purescript
677−instance showOrdering :: Show Ordering
678−```
679−
680−
681−#### `semigroupOrdering`
682−
683−``` purescript
684−instance semigroupOrdering :: Semigroup Ordering
685−```
686−
687−
688#### `Ord`
747#### `Ord`
689
748
690``` purescript
749``` purescript
@@ -700,73 +759,79 @@ The `Ord` type class represents types which support comparisons.
700- Antisymmetry: if `a <= b` and `b <= a` then `a = b`
759- Antisymmetry: if `a <= b` and `b <= a` then `a = b`
701- Transitivity: if `a <= b` and `b <= c` then `a <= c`
760- Transitivity: if `a <= b` and `b <= c` then `a <= c`
702
761
762+#### `ordBoolean`
703
763
764+``` purescript
765+instance ordBoolean :: Ord Boolean
766+```
767+
768+
704−#### `(<)`
769+#### `ordNumber`
705
770
706``` purescript
771``` purescript
707−(<) :: forall a. (Ord a) => a -> a -> Boolean
772+instance ordNumber :: Ord Number
708```
773```
709
774
710−Test whether one value is _strictly less than_ another.
711
775
712−#### `(>)`
776+#### `ordString`
713
777
714``` purescript
778``` purescript
715−(>) :: forall a. (Ord a) => a -> a -> Boolean
779+instance ordString :: Ord String
716```
780```
717
781
718−Test whether one value is _strictly greater than_ another.
719
782
720−#### `(<=)`
783+#### `ordUnit`
721
784
722``` purescript
785``` purescript
723−(<=) :: forall a. (Ord a) => a -> a -> Boolean
786+instance ordUnit :: Ord Unit
724```
787```
725
788
726−Test whether one value is _non-strictly less than_ another.
727
789
728−#### `(>=)`
790+#### `ordArray`
729
791
730``` purescript
792``` purescript
731−(>=) :: forall a. (Ord a) => a -> a -> Boolean
793+instance ordArray :: (Ord a) => Ord [a]
732```
794```
733
795
734−Test whether one value is _non-strictly greater than_ another.
735
796
736−#### `ordUnit`
797+#### `eqOrdering`
737
798
738``` purescript
799``` purescript
739−instance ordUnit :: Ord Unit
800+instance eqOrdering :: Eq Ordering
740```
801```
741
802
742
803
743−#### `ordBoolean`
804+#### `(<)`
744
805
745``` purescript
806``` purescript
746−instance ordBoolean :: Ord Boolean
807+(<) :: forall a. (Ord a) => a -> a -> Boolean
747```
808```
748
809
810+Test whether one value is _strictly less than_ another.
749
811
750−#### `ordNumber`
812+#### `(>)`
751
813
752``` purescript
814``` purescript
753−instance ordNumber :: Ord Number
815+(>) :: forall a. (Ord a) => a -> a -> Boolean
754```
816```
755
817
818+Test whether one value is _strictly greater than_ another.
756
819
757−#### `ordString`
820+#### `(<=)`
758
821
759``` purescript
822``` purescript
760−instance ordString :: Ord String
823+(<=) :: forall a. (Ord a) => a -> a -> Boolean
761```
824```
762
825
826+Test whether one value is _non-strictly less than_ another.
763
827
764−#### `ordArray`
828+#### `(>=)`
765
829
766``` purescript
830``` purescript
767−instance ordArray :: (Ord a) => Ord [a]
831+(>=) :: forall a. (Ord a) => a -> a -> Boolean
768```
832```
769
833
834+Test whether one value is _non-strictly greater than_ another.
770
835
771#### `Bounded`
836#### `Bounded`
772
837
@@ -790,6 +855,13 @@ instance boundedBoolean :: Bounded Boolean
790```
855```
791
856
792
857
858+#### `boundedUnit`
859+
860+``` purescript
861+instance boundedUnit :: Bounded Unit
862+```
863+
864+
793#### `Lattice`
865#### `Lattice`
794
866
795``` purescript
867``` purescript
@@ -824,6 +896,22 @@ instance latticeBoolean :: Lattice Boolean
824```
896```
825
897
826
898
899+#### `(||)`
900+
901+``` purescript
902+(||) :: forall a. (Lattice a) => a -> a -> a
903+```
904+
905+The `sup` operator.
906+
907+#### `(&&)`
908+
909+``` purescript
910+(&&) :: forall a. (Lattice a) => a -> a -> a
911+```
912+
913+The `inf` operator.
914+
827#### `BoundedLattice`
915#### `BoundedLattice`
828
916
829``` purescript
917``` purescript
@@ -916,66 +1004,6 @@ instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
916```
1004```
917
1005
918
1006
919−#### `(||)`
920−
921−``` purescript
922−(||) :: forall a. (Lattice a) => a -> a -> a
923−```
924−
925−The `sup` operator.
926−
927−#### `(&&)`
928−
929−``` purescript
930−(&&) :: forall a. (Lattice a) => a -> a -> a
931−```
932−
933−The `inf` operator.
934−
935−#### `Semigroup`
936−
937−``` purescript
938−class Semigroup a where
939− (<>) :: a -> a -> a
940−```
941−
942−The `Semigroup` type class identifies an associative operation on a type.
943−
944−`Semigroup` instances are required to satisfy the following law:
945−
946−- Associativity: `(x <> y) <> z = x <> (y <> z)`
947−
948−For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
949−
950−#### `semigroupUnit`
951−
952−``` purescript
953−instance semigroupUnit :: Semigroup Unit
954−```
955−
956−
957−#### `semigroupString`
958−
959−``` purescript
960−instance semigroupString :: Semigroup String
961−```
962−
963−
964−#### `semigroupArr`
965−
966−``` purescript
967−instance semigroupArr :: (Semigroup s') => Semigroup (s -> s')
968−```
969−
970−
971−#### `(++)`
972−
973−``` purescript
974−(++) :: forall s. (Semigroup s) => s -> s -> s
975−```
976−
977−`(++)` is an alias for `(<>)`.
978−
979#### `Bits`
1007#### `Bits`
980
1008
981``` purescript
1009``` purescript
prelude/prelude.purs+245−243
@@ -1,5 +1,6 @@
1module Prelude
1module Prelude
2+ ( Unit(..), unit
2− ( otherwise
3+ , otherwise
3 , flip
4 , flip
4 , const
5 , const
5 , asTypeOf
6 , asTypeOf
@@ -13,15 +14,15 @@ module Prelude
13 , Applicative, pure, liftA1
14 , Applicative, pure, liftA1
14 , Bind, (>>=)
15 , Bind, (>>=)
15 , Monad, return, liftM1, ap
16 , Monad, return, liftM1, ap
17+ , Semigroup, (<>), (++)
16 , Semiring, (+), zero, (*), one
18 , Semiring, (+), zero, (*), one
17 , ModuloSemiring, (/), mod
19 , ModuloSemiring, (/), mod
18− , Ring, (-)
20+ , Ring, (-), negate
19 , (%)
21 , (%)
20− , negate
21− , DivisionRing
22 , Num
22 , Num
23+ , DivisionRing
23 , Eq, (==), (/=)
24 , Eq, (==), (/=)
24− , Ord, Ordering(..), compare, (<), (>), (<=), (>=)
25+ , Ordering(..), Ord, compare, (<), (>), (<=), (>=)
25 , Bounded, top, bottom
26 , Bounded, top, bottom
26 , Lattice, sup, inf, (||), (&&)
27 , Lattice, sup, inf, (||), (&&)
27 , BoundedLattice
28 , BoundedLattice
@@ -29,17 +30,24 @@ module Prelude
29 , DistributiveLattice
30 , DistributiveLattice
30 , BooleanAlgebra
31 , BooleanAlgebra
31 , Bits, (.&.), (.|.), (.^.), shl, shr, zshr, complement
32 , Bits, (.&.), (.|.), (.^.), shl, shr, zshr, complement
32− , Semigroup, (<>), (++)
33− , Unit(..), unit
34 ) where
33 ) where
35
34
35+ -- | The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
36+ -- |
37+ -- | `Unit` is often used, wrapped in a monadic type constructor, as the return type of a computation where only
38+ -- | the _effects_ are important.
39+ newtype Unit = Unit {}
40+
41+ -- | `unit` is the sole inhabitant of the `Unit` type.
42+ unit :: Unit
43+ unit = Unit {}
44+
36 -- | An alias for `true`, which can be useful in guard clauses:
45 -- | An alias for `true`, which can be useful in guard clauses:
37 -- |
46 -- |
38 -- | ```purescript
47 -- | ```purescript
39 -- | max x y | x >= y = x
48 -- | max x y | x >= y = x
40 -- | | otherwise = y
49 -- | | otherwise = y
41 -- | ```
50 -- | ```
42− -- |
43 otherwise :: Boolean
51 otherwise :: Boolean
44 otherwise = true
52 otherwise = true
45
53
@@ -48,7 +56,6 @@ module Prelude
48 -- | ```purescript
56 -- | ```purescript
49 -- | flip const 1 2 = const 2 1 = 2
57 -- | flip const 1 2 = const 2 1 = 2
50 -- | ```
58 -- | ```
51− -- |
52 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
59 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
53 flip f b a = f a b
60 flip f b a = f a b
54
61
@@ -57,7 +64,6 @@ module Prelude
57 -- | ```purescript
64 -- | ```purescript
58 -- | const 1 "hello" = 1
65 -- | const 1 "hello" = 1
59 -- | ```
66 -- | ```
60− -- |
61 const :: forall a b. a -> b -> a
67 const :: forall a b. a -> b -> a
62 const a _ = a
68 const a _ = a
63
69
@@ -102,7 +108,6 @@ module Prelude
102 -- |
108 -- |
103 -- | - Left Identity: `id <<< p = p`
109 -- | - Left Identity: `id <<< p = p`
104 -- | - Right Identity: `p <<< id = p`
110 -- | - Right Identity: `p <<< id = p`
105− -- |
106 class (Semigroupoid a) <= Category a where
111 class (Semigroupoid a) <= Category a where
107 id :: forall t. a t t
112 id :: forall t. a t t
108
113
@@ -126,7 +131,6 @@ module Prelude
126 -- |
131 -- |
127 -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
132 -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
128 -- | `a $ b $ c $ d x` = `a $ (b $ (c $ (d $ x)))` = `a (b (c (d x)))`
133 -- | `a $ b $ c $ d x` = `a $ (b $ (c $ (d $ x)))` = `a (b (c (d x)))`
129− -- |
130 ($) :: forall a b. (a -> b) -> a -> b
134 ($) :: forall a b. (a -> b) -> a -> b
131 ($) f x = f x
135 ($) f x = f x
132
136
@@ -144,7 +148,6 @@ module Prelude
144 -- |
148 -- |
145 -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
149 -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
146 -- | `x # a # b # c # d` = `(((x # a) # b) # c) # d` = `d (c (b (a x)))`
150 -- | `x # a # b # c # d` = `(((x # a) # b) # c) # d` = `d (c (b (a x)))`
147− -- |
148 (#) :: forall a b. a -> (a -> b) -> b
151 (#) :: forall a b. a -> (a -> b) -> b
149 (#) x f = f x
152 (#) x f = f x
150
153
@@ -179,22 +182,26 @@ module Prelude
179 class Show a where
182 class Show a where
180 show :: a -> String
183 show :: a -> String
181
184
182− foreign import showStringImpl
185+ instance showBoolean :: Show Boolean where
183− """
186+ show true = "true"
184− function showStringImpl(s) {
187+ show false = "false"
185− return JSON.stringify(s);
186− }
187− """ :: String -> String
188
188
189− instance showUnit :: Show Unit where
189+ instance showNumber :: Show Number where
190− show (Unit {}) = "Unit {}"
190+ show = showNumberImpl
191
191
192 instance showString :: Show String where
192 instance showString :: Show String where
193 show = showStringImpl
193 show = showStringImpl
194
194
195− instance showBoolean :: Show Boolean where
195+ instance showUnit :: Show Unit where
196− show true = "true"
196+ show _ = "unit"
197− show false = "false"
197+
198+ instance showArray :: (Show a) => Show [a] where
199+ show = showArrayImpl show
200+
201+ instance showOrdering :: Show Ordering where
202+ show LT = "LT"
203+ show GT = "GT"
204+ show EQ = "EQ"
198
205
199 foreign import showNumberImpl
206 foreign import showNumberImpl
200 """
207 """
@@ -203,8 +210,12 @@ module Prelude
203 }
210 }
204 """ :: Number -> String
211 """ :: Number -> String
205
212
206− instance showNumber :: Show Number where
213+ foreign import showStringImpl
207− show = showNumberImpl
214+ """
215+ function showStringImpl(s) {
216+ return JSON.stringify(s);
217+ }
218+ """ :: String -> String
208
219
209 foreign import showArrayImpl
220 foreign import showArrayImpl
210 """
221 """
@@ -219,9 +230,6 @@ module Prelude
219 }
230 }
220 """ :: forall a. (a -> String) -> [a] -> String
231 """ :: forall a. (a -> String) -> [a] -> String
221
232
222− instance showArray :: (Show a) => Show [a] where
223− show = showArrayImpl show
224−
225 infixl 4 <$>
233 infixl 4 <$>
226 infixl 1 <#>
234 infixl 1 <#>
227
235
@@ -234,10 +242,12 @@ module Prelude
234 -- |
242 -- |
235 -- | - Identity: `(<$>) id = id`
243 -- | - Identity: `(<$>) id = id`
236 -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
244 -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
237− -- |
238 class Functor f where
245 class Functor f where
239 (<$>) :: forall a b. (a -> b) -> f a -> f b
246 (<$>) :: forall a b. (a -> b) -> f a -> f b
240
247
248+ instance functorArr :: Functor ((->) r) where
249+ (<$>) = (<<<)
250+
241 -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
251 -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
242 -- |
252 -- |
243 -- | ```purescript
253 -- | ```purescript
@@ -282,6 +292,9 @@ module Prelude
282 class (Functor f) <= Apply f where
292 class (Functor f) <= Apply f where
283 (<*>) :: forall a b. f (a -> b) -> f a -> f b
293 (<*>) :: forall a b. f (a -> b) -> f a -> f b
284
294
295+ instance applyArr :: Apply ((->) r) where
296+ (<*>) f g x = f x (g x)
297+
285 -- | The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
298 -- | The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
286 -- | create values of type `f a` from values of type `a`.
299 -- | create values of type `f a` from values of type `a`.
287 -- |
300 -- |
@@ -295,10 +308,16 @@ module Prelude
295 -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
308 -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
296 -- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
309 -- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
297 -- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
310 -- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
298− -- |
299 class (Apply f) <= Applicative f where
311 class (Apply f) <= Applicative f where
300 pure :: forall a. a -> f a
312 pure :: forall a. a -> f a
301
313
314+ instance applicativeArr :: Applicative ((->) r) where
315+ pure = const
316+
317+ -- | `return` is an alias for `pure`.
318+ return :: forall m a. (Applicative m) => a -> m a
319+ return = pure
320+
302 -- | `liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
321 -- | `liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
303 -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
322 -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
304 -- |
323 -- |
@@ -343,6 +362,9 @@ module Prelude
343 class (Apply m) <= Bind m where
362 class (Apply m) <= Bind m where
344 (>>=) :: forall a b. m a -> (a -> m b) -> m b
363 (>>=) :: forall a b. m a -> (a -> m b) -> m b
345
364
365+ instance bindArr :: Bind ((->) r) where
366+ (>>=) m f x = f (m x) x
367+
346 -- | The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
368 -- | The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
347 -- | represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
369 -- | represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
348 -- |
370 -- |
@@ -355,12 +377,9 @@ module Prelude
355 -- |
377 -- |
356 -- | - Left Identity: `do { y <- pure x ; f y } = f x`
378 -- | - Left Identity: `do { y <- pure x ; f y } = f x`
357 -- | - Right Identity: `do { y <- x ; pure y } = x`
379 -- | - Right Identity: `do { y <- x ; pure y } = x`
358− -- |
359 class (Applicative m, Bind m) <= Monad m
380 class (Applicative m, Bind m) <= Monad m
360
381
361− -- | `return` is an alias for `pure`.
382+ instance monadArr :: Monad ((->) r)
362− return :: forall m a. (Monad m) => a -> m a
363− return = pure
364
383
365 -- | `liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
384 -- | `liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
366 -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
385 -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
@@ -391,26 +410,48 @@ module Prelude
391 a' <- a
410 a' <- a
392 return (f' a')
411 return (f' a')
393
412
394− instance functorArr :: Functor ((->) r) where
413+ infixr 5 <>
395− (<$>) = (<<<)
414+ infixr 5 ++
396
415
397− instance applyArr :: Apply ((->) r) where
416+ -- | The `Semigroup` type class identifies an associative operation on a type.
398− (<*>) f g x = f x (g x)
417+ -- |
418+ -- | `Semigroup` instances are required to satisfy the following law:
419+ -- |
420+ -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
421+ -- |
422+ -- | For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
423+ class Semigroup a where
424+ (<>) :: a -> a -> a
399
425
400− instance applicativeArr :: Applicative ((->) r) where
426+ -- | `(++)` is an alias for `(<>)`.
401− pure = const
427+ (++) :: forall s. (Semigroup s) => s -> s -> s
428+ (++) = (<>)
402
429
403− instance bindArr :: Bind ((->) r) where
430+ instance semigroupString :: Semigroup String where
404− (>>=) m f x = f (m x) x
431+ (<>) = concatString
405
432
406− instance monadArr :: Monad ((->) r)
433+ instance semigroupUnit :: Semigroup Unit where
434+ (<>) _ _ = unit
407
435
408− infixl 7 *
436+ instance semigroupArr :: (Semigroup s') => Semigroup (s -> s') where
409− infixl 7 /
437+ (<>) f g = \x -> f x <> g x
410− infixl 7 %
438+
439+ instance semigroupOrdering :: Semigroup Ordering where
440+ (<>) LT _ = LT
441+ (<>) GT _ = GT
442+ (<>) EQ y = y
443+
444+ foreign import concatString
445+ """
446+ function concatString(s1) {
447+ return function(s2) {
448+ return s1 + s2;
449+ };
450+ }
451+ """ :: String -> String -> String
411
452
412− infixl 6 -
413 infixl 6 +
453 infixl 6 +
454+ infixl 7 *
414
455
415 -- | Addition and multiplication, satisfying the following laws:
456 -- | Addition and multiplication, satisfying the following laws:
416 -- |
457 -- |
@@ -418,42 +459,79 @@ module Prelude
418 -- | - `a` is a monoid under multiplication
459 -- | - `a` is a monoid under multiplication
419 -- | - multiplication distributes over addition
460 -- | - multiplication distributes over addition
420 -- | - multiplication by `zero` annihilates `a`
461 -- | - multiplication by `zero` annihilates `a`
421− -- |
422 class Semiring a where
462 class Semiring a where
423 (+) :: a -> a -> a
463 (+) :: a -> a -> a
424 zero :: a
464 zero :: a
425 (*) :: a -> a -> a
465 (*) :: a -> a -> a
426 one :: a
466 one :: a
427
467
468+ instance semiringNumber :: Semiring Number where
469+ (+) = numAdd
470+ zero = 0
471+ (*) = numMul
472+ one = 1
473+
474+ instance semiringUnit :: Semiring Unit where
475+ (+) _ _ = unit
476+ zero = unit
477+ (*) _ _ = unit
478+ one = unit
479+
480+ infixl 7 /
481+
428 -- | Addition, multiplication, modulo operation and division, satisfying:
482 -- | Addition, multiplication, modulo operation and division, satisfying:
429 -- |
483 -- |
430 -- | - ```a / b * b + (a `mod` b) = a```
484 -- | - ```a / b * b + (a `mod` b) = a```
431− -- |
432 class (Semiring a) <= ModuloSemiring a where
485 class (Semiring a) <= ModuloSemiring a where
433 (/) :: a -> a -> a
486 (/) :: a -> a -> a
434 mod :: a -> a -> a
487 mod :: a -> a -> a
435
488
489+ instance moduloSemiringNumber :: ModuloSemiring Number where
490+ (/) = numDiv
491+ mod _ _ = 0
492+
493+ instance moduloSemiringUnit :: ModuloSemiring Unit where
494+ (/) _ _ = unit
495+ mod _ _ = unit
496+
497+ infixl 6 -
498+
436 -- | Addition, multiplication, and subtraction.
499 -- | Addition, multiplication, and subtraction.
437 -- |
500 -- |
438 -- | Has the same laws as `Semiring` but additionally satisfying:
501 -- | Has the same laws as `Semiring` but additionally satisfying:
439 -- |
502 -- |
440 -- | - `a` is an abelian group under addition
503 -- | - `a` is an abelian group under addition
441− -- |
442 class (Semiring a) <= Ring a where
504 class (Semiring a) <= Ring a where
443 (-) :: a -> a -> a
505 (-) :: a -> a -> a
444
506
507+ instance ringNumber :: Ring Number where
508+ (-) = numSub
509+
510+ instance ringUnit :: Ring Unit where
511+ (-) _ _ = unit
512+
445 negate :: forall a. (Ring a) => a -> a
513 negate :: forall a. (Ring a) => a -> a
446 negate a = zero - a
514 negate a = zero - a
447
515
448 -- | Ring where every nonzero element has a multiplicative inverse so that:
516 -- | Ring where every nonzero element has a multiplicative inverse so that:
449 -- |
517 -- |
450 -- | - ```a `mod` b = zero```
518 -- | - ```a `mod` b = zero```
451− -- |
452 class (Ring a, ModuloSemiring a) <= DivisionRing a
519 class (Ring a, ModuloSemiring a) <= DivisionRing a
453
520
521+ instance divisionRingNumber :: DivisionRing Number
522+
523+ instance divisionRingUnit :: DivisionRing Unit
524+
454 -- | A commutative field
525 -- | A commutative field
455 class (DivisionRing a) <= Num a
526 class (DivisionRing a) <= Num a
456
527
528+ instance numNumber :: Num Number
529+
530+ instance numUnit :: Num Unit
531+
532+ infixl 7 %
533+ (%) = numMod
534+
457 foreign import numAdd
535 foreign import numAdd
458 """
536 """
459 function numAdd(n1) {
537 function numAdd(n1) {
@@ -463,15 +541,6 @@ module Prelude
463 }
541 }
464 """ :: Number -> Number -> Number
542 """ :: Number -> Number -> Number
465
543
466− foreign import numSub
467− """
468− function numSub(n1) {
469− return function(n2) {
470− return n1 - n2;
471− };
472− }
473− """ :: Number -> Number -> Number
474−
475 foreign import numMul
544 foreign import numMul
476 """
545 """
477 function numMul(n1) {
546 function numMul(n1) {
@@ -490,6 +559,15 @@ module Prelude
490 }
559 }
491 """ :: Number -> Number -> Number
560 """ :: Number -> Number -> Number
492
561
562+ foreign import numSub
563+ """
564+ function numSub(n1) {
565+ return function(n2) {
566+ return n1 - n2;
567+ };
568+ }
569+ """ :: Number -> Number -> Number
570+
493 foreign import numMod
571 foreign import numMod
494 """
572 """
495 function numMod(n1) {
573 function numMod(n1) {
@@ -499,35 +577,6 @@ module Prelude
499 }
577 }
500 """ :: Number -> Number -> Number
578 """ :: Number -> Number -> Number
501
579
502− (%) = numMod
503−
504− instance semiringNumber :: Semiring Number where
505− (+) = numAdd
506− zero = 0
507− (*) = numMul
508− one = 1
509−
510− instance ringNumber :: Ring Number where
511− (-) = numSub
512−
513− instance moduloSemiringNumber :: ModuloSemiring Number where
514− (/) = numDiv
515− mod _ _ = 0
516−
517− instance divisionRingNumber :: DivisionRing Number
518−
519− instance numNumber :: Num Number
520−
521− -- | The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
522− -- |
523− -- | `Unit` is often used, wrapped in a monadic type constructor, as the return type of a computation where only
524− -- | the _effects_ are important.
525− newtype Unit = Unit {}
526−
527− -- | `unit` is the sole inhabitant of the `Unit` type.
528− unit :: Unit
529− unit = Unit {}
530−
531 infix 4 ==
580 infix 4 ==
532 infix 4 /=
581 infix 4 /=
533
582
@@ -545,6 +594,26 @@ module Prelude
545 (==) :: a -> a -> Boolean
594 (==) :: a -> a -> Boolean
546 (/=) :: a -> a -> Boolean
595 (/=) :: a -> a -> Boolean
547
596
597+ instance eqBoolean :: Eq Boolean where
598+ (==) = refEq
599+ (/=) = refIneq
600+
601+ instance eqNumber :: Eq Number where
602+ (==) = refEq
603+ (/=) = refIneq
604+
605+ instance eqString :: Eq String where
606+ (==) = refEq
607+ (/=) = refIneq
608+
609+ instance eqUnit :: Eq Unit where
610+ (==) _ _ = true
611+ (/=) _ _ = false
612+
613+ instance eqArray :: (Eq a) => Eq [a] where
614+ (==) = eqArrayImpl (==)
615+ (/=) xs ys = not (xs == ys)
616+
548 foreign import refEq
617 foreign import refEq
549 """
618 """
550 function refEq(r1) {
619 function refEq(r1) {
@@ -563,22 +632,6 @@ module Prelude
563 }
632 }
564 """ :: forall a. a -> a -> Boolean
633 """ :: forall a. a -> a -> Boolean
565
634
566− instance eqUnit :: Eq Unit where
567− (==) (Unit {}) (Unit {}) = true
568− (/=) (Unit {}) (Unit {}) = false
569−
570− instance eqString :: Eq String where
571− (==) = refEq
572− (/=) = refIneq
573−
574− instance eqNumber :: Eq Number where
575− (==) = refEq
576− (/=) = refIneq
577−
578− instance eqBoolean :: Eq Boolean where
579− (==) = refEq
580− (/=) = refIneq
581−
582 foreign import eqArrayImpl
635 foreign import eqArrayImpl
583 """
636 """
584 function eqArrayImpl(f) {
637 function eqArrayImpl(f) {
@@ -594,10 +647,6 @@ module Prelude
594 }
647 }
595 """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
648 """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
596
649
597− instance eqArray :: (Eq a) => Eq [a] where
598− (==) xs ys = eqArrayImpl (==) xs ys
599− (/=) xs ys = not (xs == ys)
600−
601 -- | The `Ordering` data type represents the three possible outcomes of comparing two values:
650 -- | The `Ordering` data type represents the three possible outcomes of comparing two values:
602 -- |
651 -- |
603 -- | `LT` - The first value is _less than_ the second.
652 -- | `LT` - The first value is _less than_ the second.
@@ -605,23 +654,6 @@ module Prelude
605 -- | `EQ` - The first value is _equal to_ or _incomparable to_ the second.
654 -- | `EQ` - The first value is _equal to_ or _incomparable to_ the second.
606 data Ordering = LT | GT | EQ
655 data Ordering = LT | GT | EQ
607
656
608− instance eqOrdering :: Eq Ordering where
609− (==) LT LT = true
610− (==) GT GT = true
611− (==) EQ EQ = true
612− (==) _ _ = false
613− (/=) x y = not (x == y)
614−
615− instance showOrdering :: Show Ordering where
616− show LT = "LT"
617− show GT = "GT"
618− show EQ = "EQ"
619−
620− instance semigroupOrdering :: Semigroup Ordering where
621− (<>) LT _ = LT
622− (<>) GT _ = GT
623− (<>) EQ y = y
624−
625 -- | The `Ord` type class represents types which support comparisons.
657 -- | The `Ord` type class represents types which support comparisons.
626 -- |
658 -- |
627 -- | `Ord` instances should satisfy the laws of _partially orderings_:
659 -- | `Ord` instances should satisfy the laws of _partially orderings_:
@@ -629,11 +661,43 @@ module Prelude
629 -- | - Reflexivity: `a <= a`
661 -- | - Reflexivity: `a <= a`
630 -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
662 -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
631 -- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
663 -- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
632− -- |
633 class (Eq a) <= Ord a where
664 class (Eq a) <= Ord a where
634 compare :: a -> a -> Ordering
665 compare :: a -> a -> Ordering
635
666
667+ instance ordBoolean :: Ord Boolean where
668+ compare false false = EQ
669+ compare false true = LT
670+ compare true true = EQ
671+ compare true false = GT
672+
673+ instance ordNumber :: Ord Number where
674+ compare = unsafeCompare
675+
676+ instance ordString :: Ord String where
677+ compare = unsafeCompare
678+
679+ instance ordUnit :: Ord Unit where
680+ compare _ _ = EQ
681+
682+ instance ordArray :: (Ord a) => Ord [a] where
683+ compare [] [] = EQ
684+ compare [] _ = LT
685+ compare _ [] = GT
686+ compare (x:xs) (y:ys) = case compare x y of
687+ EQ -> compare xs ys
688+ other -> other
689+
690+ instance eqOrdering :: Eq Ordering where
691+ (==) LT LT = true
692+ (==) GT GT = true
693+ (==) EQ EQ = true
694+ (==) _ _ = false
695+ (/=) x y = not (x == y)
696+
636 infixl 4 <
697 infixl 4 <
698+ infixl 4 >
699+ infixl 4 <=
700+ infixl 4 >=
637
701
638 -- | Test whether one value is _strictly less than_ another.
702 -- | Test whether one value is _strictly less than_ another.
639 (<) :: forall a. (Ord a) => a -> a -> Boolean
703 (<) :: forall a. (Ord a) => a -> a -> Boolean
@@ -641,30 +705,27 @@ module Prelude
641 LT -> true
705 LT -> true
642 _ -> false
706 _ -> false
643
707
644− infixl 4 >
645−
646 -- | Test whether one value is _strictly greater than_ another.
708 -- | Test whether one value is _strictly greater than_ another.
647 (>) :: forall a. (Ord a) => a -> a -> Boolean
709 (>) :: forall a. (Ord a) => a -> a -> Boolean
648 (>) a1 a2 = case a1 `compare` a2 of
710 (>) a1 a2 = case a1 `compare` a2 of
649 GT -> true
711 GT -> true
650 _ -> false
712 _ -> false
651
713
652− infixl 4 <=
653−
654 -- | Test whether one value is _non-strictly less than_ another.
714 -- | Test whether one value is _non-strictly less than_ another.
655 (<=) :: forall a. (Ord a) => a -> a -> Boolean
715 (<=) :: forall a. (Ord a) => a -> a -> Boolean
656 (<=) a1 a2 = case a1 `compare` a2 of
716 (<=) a1 a2 = case a1 `compare` a2 of
657 GT -> false
717 GT -> false
658 _ -> true
718 _ -> true
659
719
660− infixl 4 >=
661−
662 -- | Test whether one value is _non-strictly greater than_ another.
720 -- | Test whether one value is _non-strictly greater than_ another.
663 (>=) :: forall a. (Ord a) => a -> a -> Boolean
721 (>=) :: forall a. (Ord a) => a -> a -> Boolean
664 (>=) a1 a2 = case a1 `compare` a2 of
722 (>=) a1 a2 = case a1 `compare` a2 of
665 LT -> false
723 LT -> false
666 _ -> true
724 _ -> true
667
725
726+ unsafeCompare :: forall a. a -> a -> Ordering
727+ unsafeCompare = unsafeCompareImpl LT EQ GT
728+
668 foreign import unsafeCompareImpl
729 foreign import unsafeCompareImpl
669 """
730 """
670 function unsafeCompareImpl(lt) {
731 function unsafeCompareImpl(lt) {
@@ -680,32 +741,6 @@ module Prelude
680 }
741 }
681 """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
742 """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
682
743
683− unsafeCompare :: forall a. a -> a -> Ordering
684− unsafeCompare = unsafeCompareImpl LT EQ GT
685−
686− instance ordUnit :: Ord Unit where
687− compare (Unit {}) (Unit {}) = EQ
688−
689− instance ordBoolean :: Ord Boolean where
690− compare false false = EQ
691− compare false true = LT
692− compare true true = EQ
693− compare true false = GT
694−
695− instance ordNumber :: Ord Number where
696− compare = unsafeCompare
697−
698− instance ordString :: Ord String where
699− compare = unsafeCompare
700−
701− instance ordArray :: (Ord a) => Ord [a] where
702− compare [] [] = EQ
703− compare [] _ = LT
704− compare _ [] = GT
705− compare (x:xs) (y:ys) = case compare x y of
706− EQ -> compare xs ys
707− other -> other
708−
709 -- | The `Bounded` type class represents types that are finite partially
744 -- | The `Bounded` type class represents types that are finite partially
710 -- | ordered sets.
745 -- | ordered sets.
711 -- |
746 -- |
@@ -720,6 +755,10 @@ module Prelude
720 top = true
755 top = true
721 bottom = false
756 bottom = false
722
757
758+ instance boundedUnit :: Bounded Unit where
759+ top = unit
760+ bottom = unit
761+
723 -- | The `Lattice` type class represents types that are partially ordered
762 -- | The `Lattice` type class represents types that are partially ordered
724 -- | sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
763 -- | sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
725 -- |
764 -- |
@@ -746,6 +785,17 @@ module Prelude
746 sup = boolOr
785 sup = boolOr
747 inf = boolAnd
786 inf = boolAnd
748
787
788+ infixr 2 ||
789+ infixr 3 &&
790+
791+ -- | The `sup` operator.
792+ (||) :: forall a. (Lattice a) => a -> a -> a
793+ (||) = sup
794+
795+ -- | The `inf` operator.
796+ (&&) :: forall a. (Lattice a) => a -> a -> a
797+ (&&) = inf
798+
749 -- | The `BoundedLattice` type class represents types that are finite
799 -- | The `BoundedLattice` type class represents types that are finite
750 -- | lattices.
800 -- | lattices.
751 -- |
801 -- |
@@ -799,35 +849,23 @@ module Prelude
799
849
800 instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
850 instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
801
851
802− infixr 2 ||
803−
804− -- | The `sup` operator.
805− (||) :: forall a. (Lattice a) => a -> a -> a
806− (||) = sup
807−
808− infixr 3 &&
809−
810− -- | The `inf` operator.
811− (&&) :: forall a. (Lattice a) => a -> a -> a
812− (&&) = inf
813−
814− foreign import boolAnd
852+ foreign import boolOr
815 """
853 """
816− function boolAnd(b1) {
854+ function boolOr(b1) {
817 return function(b2) {
855 return function(b2) {
818− return b1 && b2;
856+ return b1 || b2;
819 };
857 };
820 }
858 }
821− """ :: Boolean -> Boolean -> Boolean
859+ """ :: Boolean -> Boolean -> Boolean
822
860
823− foreign import boolOr
861+ foreign import boolAnd
824 """
862 """
825− function boolOr(b1) {
863+ function boolAnd(b1) {
826 return function(b2) {
864 return function(b2) {
827− return b1 || b2;
865+ return b1 && b2;
828 };
866 };
829 }
867 }
830− """ :: Boolean -> Boolean -> Boolean
868+ """ :: Boolean -> Boolean -> Boolean
831
869
832 foreign import boolNot
870 foreign import boolNot
833 """
871 """
@@ -836,42 +874,6 @@ module Prelude
836 }
874 }
837 """ :: Boolean -> Boolean
875 """ :: Boolean -> Boolean
838
876
839− infixr 5 <>
840−
841− -- | The `Semigroup` type class identifies an associative operation on a type.
842− -- |
843− -- | `Semigroup` instances are required to satisfy the following law:
844− -- |
845− -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
846− -- |
847− -- | For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
848− class Semigroup a where
849− (<>) :: a -> a -> a
850−
851− foreign import concatString
852− """
853− function concatString(s1) {
854− return function(s2) {
855− return s1 + s2;
856− };
857− }
858− """ :: String -> String -> String
859−
860− instance semigroupUnit :: Semigroup Unit where
861− (<>) (Unit {}) (Unit {}) = Unit {}
862−
863− instance semigroupString :: Semigroup String where
864− (<>) = concatString
865−
866− instance semigroupArr :: (Semigroup s') => Semigroup (s -> s') where
867− (<>) f g = \x -> f x <> g x
868−
869− infixr 5 ++
870−
871− -- | `(++)` is an alias for `(<>)`.
872− (++) :: forall s. (Semigroup s) => s -> s -> s
873− (++) = (<>)
874−
875 infixl 10 .&.
877 infixl 10 .&.
876 infixl 10 .|.
878 infixl 10 .|.
877 infixl 10 .^.
879 infixl 10 .^.
@@ -886,56 +888,65 @@ module Prelude
886 zshr :: b -> Number -> b
888 zshr :: b -> Number -> b
887 complement :: b -> b
889 complement :: b -> b
888
890
891+ instance bitsNumber :: Bits Number where
892+ (.&.) = numAnd
893+ (.|.) = numOr
894+ (.^.) = numXor
895+ shl = numShl
896+ shr = numShr
897+ zshr = numZshr
898+ complement = numComplement
899+
889− foreign import numShl
900+ foreign import numAnd
890 """
901 """
891− function numShl(n1) {
902+ function numAnd(n1) {
892 return function(n2) {
903 return function(n2) {
893− return n1 << n2;
904+ return n1 & n2;
894 };
905 };
895 }
906 }
896 """ :: Number -> Number -> Number
907 """ :: Number -> Number -> Number
897
908
898− foreign import numShr
909+ foreign import numOr
899 """
910 """
900− function numShr(n1) {
911+ function numOr(n1) {
901 return function(n2) {
912 return function(n2) {
902− return n1 >> n2;
913+ return n1 | n2;
903 };
914 };
904 }
915 }
905 """ :: Number -> Number -> Number
916 """ :: Number -> Number -> Number
906
917
907− foreign import numZshr
918+ foreign import numXor
908 """
919 """
909− function numZshr(n1) {
920+ function numXor(n1) {
910 return function(n2) {
921 return function(n2) {
911− return n1 >>> n2;
922+ return n1 ^ n2;
912 };
923 };
913 }
924 }
914 """ :: Number -> Number -> Number
925 """ :: Number -> Number -> Number
915
926
916− foreign import numAnd
927+ foreign import numShl
917 """
928 """
918− function numAnd(n1) {
929+ function numShl(n1) {
919 return function(n2) {
930 return function(n2) {
920− return n1 & n2;
931+ return n1 << n2;
921 };
932 };
922 }
933 }
923 """ :: Number -> Number -> Number
934 """ :: Number -> Number -> Number
924
935
925− foreign import numOr
936+ foreign import numShr
926 """
937 """
927− function numOr(n1) {
938+ function numShr(n1) {
928 return function(n2) {
939 return function(n2) {
929− return n1 | n2;
940+ return n1 >> n2;
930 };
941 };
931 }
942 }
932 """ :: Number -> Number -> Number
943 """ :: Number -> Number -> Number
933
944
934− foreign import numXor
945+ foreign import numZshr
935 """
946 """
936− function numXor(n1) {
947+ function numZshr(n1) {
937 return function(n2) {
948 return function(n2) {
938− return n1 ^ n2;
949+ return n1 >>> n2;
939 };
950 };
940 }
951 }
941 """ :: Number -> Number -> Number
952 """ :: Number -> Number -> Number
@@ -947,15 +958,6 @@ module Prelude
947 }
958 }
948 """ :: Number -> Number
959 """ :: Number -> Number
949
960
950− instance bitsNumber :: Bits Number where
951− (.&.) = numAnd
952− (.|.) = numOr
953− (.^.) = numXor
954− shl = numShl
955− shr = numShr
956− zshr = numZshr
957− complement = numComplement
958−
959module Data.Function where
961module Data.Function where
960
962
961 -- | The `on` function is used to change the domain of a binary operator.
963 -- | The `on` function is used to change the domain of a binary operator.