@@ -1,5 +1,6 @@
11module Prelude
2− ( otherwise
2+ ( Unit(..), unit
3+ , otherwise
34 , flip
45 , const
56 , asTypeOf
@@ -13,15 +14,15 @@ module Prelude
1314 , Applicative, pure, liftA1
1415 , Bind, (>>=)
1516 , Monad, return, liftM1, ap
17+ , Semigroup, (<>), (++)
1618 , Semiring, (+), zero, (*), one
1719 , ModuloSemiring, (/), mod
18− , Ring, (-)
20+ , Ring, (-), negate
1921 , (%)
20− , negate
21− , DivisionRing
2222 , Num
23+ , DivisionRing
2324 , Eq, (==), (/=)
24− , Ord, Ordering(..), compare, (<), (>), (<=), (>=)
25+ , Ordering(..), Ord, compare, (<), (>), (<=), (>=)
2526 , Bounded, top, bottom
2627 , Lattice, sup, inf, (||), (&&)
2728 , BoundedLattice
@@ -29,17 +30,24 @@ module Prelude
2930 , DistributiveLattice
3031 , BooleanAlgebra
3132 , Bits, (.&.), (.|.), (.^.), shl, shr, zshr, complement
32− , Semigroup, (<>), (++)
33− , Unit(..), unit
3433 ) where
3534
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+
3645 -- | An alias for `true`, which can be useful in guard clauses:
3746 -- |
3847 -- | ```purescript
3948 -- | max x y | x >= y = x
4049 -- | | otherwise = y
4150 -- | ```
42− -- |
4351 otherwise :: Boolean
4452 otherwise = true
4553
@@ -48,7 +56,6 @@ module Prelude
4856 -- | ```purescript
4957 -- | flip const 1 2 = const 2 1 = 2
5058 -- | ```
51− -- |
5259 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
5360 flip f b a = f a b
5461
@@ -57,7 +64,6 @@ module Prelude
5764 -- | ```purescript
5865 -- | const 1 "hello" = 1
5966 -- | ```
60− -- |
6167 const :: forall a b. a -> b -> a
6268 const a _ = a
6369
@@ -102,7 +108,6 @@ module Prelude
102108 -- |
103109 -- | - Left Identity: `id <<< p = p`
104110 -- | - Right Identity: `p <<< id = p`
105− -- |
106111 class (Semigroupoid a) <= Category a where
107112 id :: forall t. a t t
108113
@@ -126,7 +131,6 @@ module Prelude
126131 -- |
127132 -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
128133 -- | `a $ b $ c $ d x` = `a $ (b $ (c $ (d $ x)))` = `a (b (c (d x)))`
129− -- |
130134 ($) :: forall a b. (a -> b) -> a -> b
131135 ($) f x = f x
132136
@@ -144,7 +148,6 @@ module Prelude
144148 -- |
145149 -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
146150 -- | `x # a # b # c # d` = `(((x # a) # b) # c) # d` = `d (c (b (a x)))`
147− -- |
148151 (#) :: forall a b. a -> (a -> b) -> b
149152 (#) x f = f x
150153
@@ -179,22 +182,26 @@ module Prelude
179182 class Show a where
180183 show :: a -> String
181184
182− foreign import showStringImpl
183− """
184− function showStringImpl(s) {
185− return JSON.stringify(s);
186− }
187− """ :: String -> String
185+ instance showBoolean :: Show Boolean where
186+ show true = "true"
187+ show false = "false"
188188
189− instance showUnit :: Show Unit where
190− show (Unit {}) = "Unit {}"
189+ instance showNumber :: Show Number where
190+ show = showNumberImpl
191191
192192 instance showString :: Show String where
193193 show = showStringImpl
194194
195− instance showBoolean :: Show Boolean where
196− show true = "true"
197− show false = "false"
195+ instance showUnit :: Show Unit where
196+ show _ = "unit"
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"
198205
199206 foreign import showNumberImpl
200207 """
@@ -203,8 +210,12 @@ module Prelude
203210 }
204211 """ :: Number -> String
205212
206− instance showNumber :: Show Number where
207− show = showNumberImpl
213+ foreign import showStringImpl
214+ """
215+ function showStringImpl(s) {
216+ return JSON.stringify(s);
217+ }
218+ """ :: String -> String
208219
209220 foreign import showArrayImpl
210221 """
@@ -219,9 +230,6 @@ module Prelude
219230 }
220231 """ :: forall a. (a -> String) -> [a] -> String
221232
222− instance showArray :: (Show a) => Show [a] where
223− show = showArrayImpl show
224−
225233 infixl 4 <$>
226234 infixl 1 <#>
227235
@@ -234,10 +242,12 @@ module Prelude
234242 -- |
235243 -- | - Identity: `(<$>) id = id`
236244 -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
237− -- |
238245 class Functor f where
239246 (<$>) :: forall a b. (a -> b) -> f a -> f b
240247
248+ instance functorArr :: Functor ((->) r) where
249+ (<$>) = (<<<)
250+
241251 -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
242252 -- |
243253 -- | ```purescript
@@ -282,6 +292,9 @@ module Prelude
282292 class (Functor f) <= Apply f where
283293 (<*>) :: forall a b. f (a -> b) -> f a -> f b
284294
295+ instance applyArr :: Apply ((->) r) where
296+ (<*>) f g x = f x (g x)
297+
285298 -- | The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
286299 -- | create values of type `f a` from values of type `a`.
287300 -- |
@@ -295,10 +308,16 @@ module Prelude
295308 -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
296309 -- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
297310 -- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
298− -- |
299311 class (Apply f) <= Applicative f where
300312 pure :: forall a. a -> f a
301313
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+
302321 -- | `liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
303322 -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
304323 -- |
@@ -343,6 +362,9 @@ module Prelude
343362 class (Apply m) <= Bind m where
344363 (>>=) :: forall a b. m a -> (a -> m b) -> m b
345364
365+ instance bindArr :: Bind ((->) r) where
366+ (>>=) m f x = f (m x) x
367+
346368 -- | The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
347369 -- | represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
348370 -- |
@@ -355,12 +377,9 @@ module Prelude
355377 -- |
356378 -- | - Left Identity: `do { y <- pure x ; f y } = f x`
357379 -- | - Right Identity: `do { y <- x ; pure y } = x`
358− -- |
359380 class (Applicative m, Bind m) <= Monad m
360381
361− -- | `return` is an alias for `pure`.
362− return :: forall m a. (Monad m) => a -> m a
363− return = pure
382+ instance monadArr :: Monad ((->) r)
364383
365384 -- | `liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
366385 -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
@@ -391,26 +410,48 @@ module Prelude
391410 a' <- a
392411 return (f' a')
393412
394− instance functorArr :: Functor ((->) r) where
395− (<$>) = (<<<)
413+ infixr 5 <>
414+ infixr 5 ++
396415
397− instance applyArr :: Apply ((->) r) where
398− (<*>) f g x = f x (g x)
416+ -- | The `Semigroup` type class identifies an associative operation on a type.
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
399425
400− instance applicativeArr :: Applicative ((->) r) where
401− pure = const
426+ -- | `(++)` is an alias for `(<>)`.
427+ (++) :: forall s. (Semigroup s) => s -> s -> s
428+ (++) = (<>)
402429
403− instance bindArr :: Bind ((->) r) where
404− (>>=) m f x = f (m x) x
430+ instance semigroupString :: Semigroup String where
431+ (<>) = concatString
405432
406− instance monadArr :: Monad ((->) r)
433+ instance semigroupUnit :: Semigroup Unit where
434+ (<>) _ _ = unit
407435
408− infixl 7 *
409− infixl 7 /
410− infixl 7 %
436+ instance semigroupArr :: (Semigroup s') => Semigroup (s -> s') where
437+ (<>) f g = \x -> f x <> g x
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
411452
412− infixl 6 -
413453 infixl 6 +
454+ infixl 7 *
414455
415456 -- | Addition and multiplication, satisfying the following laws:
416457 -- |
@@ -418,42 +459,79 @@ module Prelude
418459 -- | - `a` is a monoid under multiplication
419460 -- | - multiplication distributes over addition
420461 -- | - multiplication by `zero` annihilates `a`
421− -- |
422462 class Semiring a where
423463 (+) :: a -> a -> a
424464 zero :: a
425465 (*) :: a -> a -> a
426466 one :: a
427467
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+
428482 -- | Addition, multiplication, modulo operation and division, satisfying:
429483 -- |
430484 -- | - ```a / b * b + (a `mod` b) = a```
431− -- |
432485 class (Semiring a) <= ModuloSemiring a where
433486 (/) :: a -> a -> a
434487 mod :: a -> a -> a
435488
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+
436499 -- | Addition, multiplication, and subtraction.
437500 -- |
438501 -- | Has the same laws as `Semiring` but additionally satisfying:
439502 -- |
440503 -- | - `a` is an abelian group under addition
441− -- |
442504 class (Semiring a) <= Ring a where
443505 (-) :: a -> a -> a
444506
507+ instance ringNumber :: Ring Number where
508+ (-) = numSub
509+
510+ instance ringUnit :: Ring Unit where
511+ (-) _ _ = unit
512+
445513 negate :: forall a. (Ring a) => a -> a
446514 negate a = zero - a
447515
448516 -- | Ring where every nonzero element has a multiplicative inverse so that:
449517 -- |
450518 -- | - ```a `mod` b = zero```
451− -- |
452519 class (Ring a, ModuloSemiring a) <= DivisionRing a
453520
521+ instance divisionRingNumber :: DivisionRing Number
522+
523+ instance divisionRingUnit :: DivisionRing Unit
524+
454525 -- | A commutative field
455526 class (DivisionRing a) <= Num a
456527
528+ instance numNumber :: Num Number
529+
530+ instance numUnit :: Num Unit
531+
532+ infixl 7 %
533+ (%) = numMod
534+
457535 foreign import numAdd
458536 """
459537 function numAdd(n1) {
@@ -463,15 +541,6 @@ module Prelude
463541 }
464542 """ :: Number -> Number -> Number
465543
466− foreign import numSub
467− """
468− function numSub(n1) {
469− return function(n2) {
470− return n1 - n2;
471− };
472− }
473− """ :: Number -> Number -> Number
474−
475544 foreign import numMul
476545 """
477546 function numMul(n1) {
@@ -490,6 +559,15 @@ module Prelude
490559 }
491560 """ :: Number -> Number -> Number
492561
562+ foreign import numSub
563+ """
564+ function numSub(n1) {
565+ return function(n2) {
566+ return n1 - n2;
567+ };
568+ }
569+ """ :: Number -> Number -> Number
570+
493571 foreign import numMod
494572 """
495573 function numMod(n1) {
@@ -499,35 +577,6 @@ module Prelude
499577 }
500578 """ :: Number -> Number -> Number
501579
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−
531580 infix 4 ==
532581 infix 4 /=
533582
@@ -545,6 +594,26 @@ module Prelude
545594 (==) :: a -> a -> Boolean
546595 (/=) :: a -> a -> Boolean
547596
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+
548617 foreign import refEq
549618 """
550619 function refEq(r1) {
@@ -563,22 +632,6 @@ module Prelude
563632 }
564633 """ :: forall a. a -> a -> Boolean
565634
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−
582635 foreign import eqArrayImpl
583636 """
584637 function eqArrayImpl(f) {
@@ -594,10 +647,6 @@ module Prelude
594647 }
595648 """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
596649
597− instance eqArray :: (Eq a) => Eq [a] where
598− (==) xs ys = eqArrayImpl (==) xs ys
599− (/=) xs ys = not (xs == ys)
600−
601650 -- | The `Ordering` data type represents the three possible outcomes of comparing two values:
602651 -- |
603652 -- | `LT` - The first value is _less than_ the second.
@@ -605,23 +654,6 @@ module Prelude
605654 -- | `EQ` - The first value is _equal to_ or _incomparable to_ the second.
606655 data Ordering = LT | GT | EQ
607656
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−
625657 -- | The `Ord` type class represents types which support comparisons.
626658 -- |
627659 -- | `Ord` instances should satisfy the laws of _partially orderings_:
@@ -629,11 +661,43 @@ module Prelude
629661 -- | - Reflexivity: `a <= a`
630662 -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
631663 -- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
632− -- |
633664 class (Eq a) <= Ord a where
634665 compare :: a -> a -> Ordering
635666
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+
636697 infixl 4 <
698+ infixl 4 >
699+ infixl 4 <=
700+ infixl 4 >=
637701
638702 -- | Test whether one value is _strictly less than_ another.
639703 (<) :: forall a. (Ord a) => a -> a -> Boolean
@@ -641,30 +705,27 @@ module Prelude
641705 LT -> true
642706 _ -> false
643707
644− infixl 4 >
645−
646708 -- | Test whether one value is _strictly greater than_ another.
647709 (>) :: forall a. (Ord a) => a -> a -> Boolean
648710 (>) a1 a2 = case a1 `compare` a2 of
649711 GT -> true
650712 _ -> false
651713
652− infixl 4 <=
653−
654714 -- | Test whether one value is _non-strictly less than_ another.
655715 (<=) :: forall a. (Ord a) => a -> a -> Boolean
656716 (<=) a1 a2 = case a1 `compare` a2 of
657717 GT -> false
658718 _ -> true
659719
660− infixl 4 >=
661−
662720 -- | Test whether one value is _non-strictly greater than_ another.
663721 (>=) :: forall a. (Ord a) => a -> a -> Boolean
664722 (>=) a1 a2 = case a1 `compare` a2 of
665723 LT -> false
666724 _ -> true
667725
726+ unsafeCompare :: forall a. a -> a -> Ordering
727+ unsafeCompare = unsafeCompareImpl LT EQ GT
728+
668729 foreign import unsafeCompareImpl
669730 """
670731 function unsafeCompareImpl(lt) {
@@ -680,32 +741,6 @@ module Prelude
680741 }
681742 """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
682743
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−
709744 -- | The `Bounded` type class represents types that are finite partially
710745 -- | ordered sets.
711746 -- |
@@ -720,6 +755,10 @@ module Prelude
720755 top = true
721756 bottom = false
722757
758+ instance boundedUnit :: Bounded Unit where
759+ top = unit
760+ bottom = unit
761+
723762 -- | The `Lattice` type class represents types that are partially ordered
724763 -- | sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
725764 -- |
@@ -746,6 +785,17 @@ module Prelude
746785 sup = boolOr
747786 inf = boolAnd
748787
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+
749799 -- | The `BoundedLattice` type class represents types that are finite
750800 -- | lattices.
751801 -- |
@@ -799,35 +849,23 @@ module Prelude
799849
800850 instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
801851
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
815853 """
816− function boolAnd(b1) {
854+ function boolOr(b1) {
817855 return function(b2) {
818− return b1 && b2;
856+ return b1 || b2;
819857 };
820858 }
821− """ :: Boolean -> Boolean -> Boolean
859+ """ :: Boolean -> Boolean -> Boolean
822860
823− foreign import boolOr
861+ foreign import boolAnd
824862 """
825− function boolOr(b1) {
863+ function boolAnd(b1) {
826864 return function(b2) {
827− return b1 || b2;
865+ return b1 && b2;
828866 };
829867 }
830− """ :: Boolean -> Boolean -> Boolean
868+ """ :: Boolean -> Boolean -> Boolean
831869
832870 foreign import boolNot
833871 """
@@ -836,42 +874,6 @@ module Prelude
836874 }
837875 """ :: Boolean -> Boolean
838876
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−
875877 infixl 10 .&.
876878 infixl 10 .|.
877879 infixl 10 .^.
@@ -886,56 +888,65 @@ module Prelude
886888 zshr :: b -> Number -> b
887889 complement :: b -> b
888890
889− foreign import numShl
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+
900+ foreign import numAnd
890901 """
891− function numShl(n1) {
902+ function numAnd(n1) {
892903 return function(n2) {
893− return n1 << n2;
904+ return n1 & n2;
894905 };
895906 }
896907 """ :: Number -> Number -> Number
897908
898− foreign import numShr
909+ foreign import numOr
899910 """
900− function numShr(n1) {
911+ function numOr(n1) {
901912 return function(n2) {
902− return n1 >> n2;
913+ return n1 | n2;
903914 };
904915 }
905916 """ :: Number -> Number -> Number
906917
907− foreign import numZshr
918+ foreign import numXor
908919 """
909− function numZshr(n1) {
920+ function numXor(n1) {
910921 return function(n2) {
911− return n1 >>> n2;
922+ return n1 ^ n2;
912923 };
913924 }
914925 """ :: Number -> Number -> Number
915926
916− foreign import numAnd
927+ foreign import numShl
917928 """
918− function numAnd(n1) {
929+ function numShl(n1) {
919930 return function(n2) {
920− return n1 & n2;
931+ return n1 << n2;
921932 };
922933 }
923934 """ :: Number -> Number -> Number
924935
925− foreign import numOr
936+ foreign import numShr
926937 """
927− function numOr(n1) {
938+ function numShr(n1) {
928939 return function(n2) {
929− return n1 | n2;
940+ return n1 >> n2;
930941 };
931942 }
932943 """ :: Number -> Number -> Number
933944
934− foreign import numXor
945+ foreign import numZshr
935946 """
936− function numXor(n1) {
947+ function numZshr(n1) {
937948 return function(n2) {
938− return n1 ^ n2;
949+ return n1 >>> n2;
939950 };
940951 }
941952 """ :: Number -> Number -> Number
@@ -947,15 +958,6 @@ module Prelude
947958 }
948959 """ :: Number -> Number
949960
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−
959961module Data.Function where
960962
961963 -- | The `on` function is used to change the domain of a binary operator.