git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Break up `BoolLike`
7390237Gary Burgess
examples/passing/OperatorInlining.pursnew file+46
@@ -0,0 +1,46 @@
1+module Main where
2+
3+import Debug.Trace
4+
5+main = do
6+
7+ -- semiringNumber
8+ print (1 + 2)
9+ print (1 * 2)
10+
11+ -- ringNumber
12+ print (1 - 2)
13+ print (negate 1)
14+
15+ -- moduleSemiringNumber
16+ print (1 / 2)
17+
18+ -- ordNumber
19+ print (1 > 2)
20+ print (1 < 2)
21+ print (1 <= 2)
22+ print (1 >= 2)
23+ print (1 == 2)
24+
25+ -- eqNumber
26+ print (1 == 2)
27+ print (1 /= 2)
28+
29+ -- eqString
30+ print ("foo" == "bar")
31+ print ("foo" /= "bar")
32+
33+ -- eqBoolean
34+ print (true == false)
35+ print (true /= false)
36+
37+ -- semigroupString
38+ print ("foo" ++ "bar")
39+ print ("foo" <> "bar")
40+
41+ -- latticeBoolean
42+ print (top && true)
43+ print (bottom || false)
44+
45+ -- complementedLatticeBoolean
46+ print (not true)
prelude/README.md+180−51
@@ -119,16 +119,16 @@ instance categoryArr :: Category Prim.Function
119($) :: forall a b. (a -> b) -> a -> b
119($) :: forall a b. (a -> b) -> a -> b
120```
120```
121
121
122−Applies a function to its argument
122+Applies a function to its argument.
123
123
124```purescript
124```purescript
125−length $ groupBy productCategory $ filter isInStock products
125+length $ groupBy productCategory $ filter isInStock $ products
126```
126```
127
127
128is equivalent to
128is equivalent to
129
129
130```purescript
130```purescript
131−length (groupBy productCategory (filter isInStock (products)))
131+length (groupBy productCategory (filter isInStock products))
132```
132```
133
133
134`($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
134`($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
@@ -141,16 +141,16 @@ length (groupBy productCategory (filter isInStock (products)))
141(#) :: forall a b. a -> (a -> b) -> b
141(#) :: forall a b. a -> (a -> b) -> b
142```
142```
143
143
144−Applies a function to its argument
144+Applies an argument to a function.
145
145
146```purescript
146```purescript
147−products # groupBy productCategory # filter isInStock # length
147+products # filter isInStock # groupBy productCategory # length
148```
148```
149
149
150is equivalent to
150is equivalent to
151
151
152```purescript
152```purescript
153−length (groupBy productCategory (filter isInStock (products)))
153+length (groupBy productCategory (filter isInStock products))
154```
154```
155
155
156`(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
156`(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
@@ -190,7 +190,7 @@ class Show a where
190
190
191The `Show` type class represents those types which can be converted into a human-readable `String` representation.
191The `Show` type class represents those types which can be converted into a human-readable `String` representation.
192
192
193−While not required, it is recommended that for any expression `x`, the string `show x` be executable PureScript code
193+While 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`.
194which evaluates to the same value as the expression `x`.
195
195
196#### `showUnit`
196#### `showUnit`
@@ -264,7 +264,7 @@ types use the type constructor `f` to represent some computational context.
264void :: forall f a. (Functor f) => f a -> f Unit
264void :: forall f a. (Functor f) => f a -> f Unit
265```
265```
266
266
267−The `void` function is used to ignore the type wrapped by a [`Functor`](#functor), replacing it with `Unit` and
267+The `void` function is used to ignore the type wrapped by a [`Functor`](#functor), replacing it with `Unit` and
268keeping only the type information provided by the type constructor itself.
268keeping only the type information provided by the type constructor itself.
269
269
270`void` is often useful when using `do` notation to change the return type of a monadic computation:
270`void` is often useful when using `do` notation to change the return type of a monadic computation:
@@ -311,8 +311,8 @@ class (Apply f) <= Applicative f where
311The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
311The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
312create values of type `f a` from values of type `a`.
312create values of type `f a` from values of type `a`.
313
313
314−Where [`Apply`](#apply) provides the ability to lift functions of two or more arguments to functions whose arguments are wrapped using `f`,
314+Where [`Apply`](#apply) provides the ability to lift functions of two or more arguments to functions whose arguments are wrapped using `f`,
315−and [`Functor`](#functor) provides the ability to lift functions of one argument, `pure` can be seen as the function which lifts functions of
315+and [`Functor`](#functor) provides the ability to lift functions of one argument, `pure` can be seen as the function which lifts functions of
316_zero_ arguments. That is, `Applicative` functors support a lifting operation for any number of function arguments.
316_zero_ arguments. That is, `Applicative` functors support a lifting operation for any number of function arguments.
317
317
318`Applicative` instances should satisfy the following laws:
318`Applicative` instances should satisfy the following laws:
@@ -362,7 +362,7 @@ where the function argument of `f` is given the name `y`.
362
362
363- Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
363- Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
364
364
365−Or, expressed using `do` notation:
365+Or, expressed using `do` notation:
366
366
367- Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
367- Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
368
368
@@ -388,7 +388,7 @@ represent type constructors which support sequential composition, and also lifti
388- Left Identity: `pure x >>= f = f x`
388- Left Identity: `pure x >>= f = f x`
389- Right Identity: `x >>= pure = x`
389- Right Identity: `x >>= pure = x`
390
390
391−Or, expressed using `do` notation:
391+Or, expressed using `do` notation:
392
392
393- Left Identity: `do { y <- pure x ; f y } = f x`
393- Left Identity: `do { y <- pure x ; f y } = f x`
394- Right Identity: `do { y <- x ; pure y } = x`
394- Right Identity: `do { y <- x ; pure y } = x`
@@ -612,21 +612,7 @@ The `Eq` type class represents types which support decidable equality.
612- Transitivity: if `x == y` and `y == z` then `x == z`
612- Transitivity: if `x == y` and `y == z` then `x == z`
613- Negation: `x /= y = not (x == y)`
613- Negation: `x /= y = not (x == y)`
614
614
615−`(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
615+`(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
616−
617−#### `refEq`
618−
619−``` purescript
620−refEq :: forall a. a -> a -> Boolean
621−```
622−
623−
624−#### `refIneq`
625−
626−``` purescript
627−refIneq :: forall a. a -> a -> Boolean
628−```
629−
630
616
631#### `eqUnit`
617#### `eqUnit`
632
618
@@ -782,49 +768,170 @@ instance ordArray :: (Ord a) => Ord [a]
782```
768```
783
769
784
770
785−#### `Bits`
771+#### `Bounded`
786
772
787``` purescript
773``` purescript
788−class Bits b where
774+class (Ord a) <= Bounded a where
789− (.&.) :: b -> b -> b
775+ top :: a
790− (.|.) :: b -> b -> b
776+ bottom :: a
791− (.^.) :: b -> b -> b
792− shl :: b -> Number -> b
793− shr :: b -> Number -> b
794− zshr :: b -> Number -> b
795− complement :: b -> b
796```
777```
797
778
798−The `Bits` type class identifies types which support bitwise operations.
779+The `Bounded` type class represents types that are finite partially
780+ordered sets.
799
781
800−#### `bitsNumber`
782+Instances should satisfy the following law in addition to the `Ord` laws:
783+
784+- Ordering: `bottom <= a <= top`
785+
786+#### `boundedBoolean`
801
787
802``` purescript
788``` purescript
803−instance bitsNumber :: Bits Number
789+instance boundedBoolean :: Bounded Boolean
790+```
791+
792+
793+#### `Lattice`
794+
795+``` purescript
796+class (Ord a) <= Lattice a where
797+ sup :: a -> a -> a
798+ inf :: a -> a -> a
799+```
800+
801+The `Lattice` type class represents types that are partially ordered
802+sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
803+
804+Instances should satisfy the following laws in addition to the `Ord`
805+laws:
806+
807+- Associativity:
808+ - `a || (b || c) = (a || b) || c`
809+ - `a && (b && c) = (a && b) && c`
810+- Commutativity:
811+ - `a || b = b || a`
812+ - `a && b = b && a`
813+- Absorption:
814+ - `a || (a && b) = a`
815+ - `a && (a || b) = a`
816+- Idempotent:
817+ - `a || a = a`
818+ - `a && a = a`
819+
820+#### `latticeBoolean`
821+
822+``` purescript
823+instance latticeBoolean :: Lattice Boolean
824+```
825+
826+
827+#### `BoundedLattice`
828+
829+``` purescript
830+class (Bounded a, Lattice a) <= BoundedLattice a where
804```
831```
805
832
833+The `BoundedLattice` type class represents types that are finite
834+lattices.
835+
836+Instances should satisfy the following law in addition to the `Lattice`
837+and `Bounded` laws:
838+
839+- Identity:
840+ - `a || bottom = a`
841+ - `a && top = a`
842+- Annihiliation:
843+ - `a || top = top`
844+ - `a && bottom = bottom`
806
845
807−#### `BoolLike`
846+#### `boundedLatticeBoolean`
808
847
809``` purescript
848``` purescript
810−class BoolLike b where
849+instance boundedLatticeBoolean :: BoundedLattice Boolean
811− (&&) :: b -> b -> b
812− (||) :: b -> b -> b
813− not :: b -> b
814```
850```
815
851
816−The `BoolLike` type class identifies types which support Boolean operations.
817
852
818−`BoolLike` instances are required to satisfy the laws of a _Boolean algebra_.
853+#### `ComplementedLattice`
854+
855+``` purescript
856+class (BoundedLattice a) <= ComplementedLattice a where
857+ not :: a -> a
858+```
819
859
860+The `ComplementedLattice` type class represents types that are lattices
861+where every member is also uniquely complemented.
820
862
821−#### `boolLikeBoolean`
863+Instances should satisfy the following law in addition to the
864+`BoundedLattice` laws:
865+
866+- Complemented:
867+ - `not a || a == top`
868+ - `not a && a == bottom`
869+- Double negation:
870+ - `not <<< not == id`
871+
872+#### `complementedLatticeBoolean`
822
873
823``` purescript
874``` purescript
824−instance boolLikeBoolean :: BoolLike Boolean
875+instance complementedLatticeBoolean :: ComplementedLattice Boolean
825```
876```
826
877
827
878
879+#### `DistributiveLattice`
880+
881+``` purescript
882+class (Lattice a) <= DistributiveLattice a where
883+```
884+
885+The `DistributiveLattice` type class represents types that are lattices
886+where the `&&` and `||` distribute over each other.
887+
888+Instances should satisfy the following law in addition to the `Lattice`
889+laws:
890+
891+- Distributivity: `x && (y || z) = (x && y) || (x && z)`
892+
893+#### `distributiveLatticeBoolean`
894+
895+``` purescript
896+instance distributiveLatticeBoolean :: DistributiveLattice Boolean
897+```
898+
899+
900+#### `BooleanAlgebra`
901+
902+``` purescript
903+class (ComplementedLattice a, DistributiveLattice a) <= BooleanAlgebra a where
904+```
905+
906+The `BooleanAlgebra` type class represents types that are Boolean
907+algebras, also known as Boolean lattices.
908+
909+Instances should satisfy the `ComplementedLattice` and
910+`DistributiveLattice` laws.
911+
912+#### `booleanAlgebraBoolean`
913+
914+``` purescript
915+instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
916+```
917+
918+
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+
828#### `Semigroup`
935#### `Semigroup`
829
936
830``` purescript
937``` purescript
@@ -838,7 +945,7 @@ The `Semigroup` type class identifies an associative operation on a type.
838
945
839- Associativity: `(x <> y) <> z = x <> (y <> z)`
946- Associativity: `(x <> y) <> z = x <> (y <> z)`
840
947
841−For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
948+For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
842
949
843#### `semigroupUnit`
950#### `semigroupUnit`
844
951
@@ -869,6 +976,28 @@ instance semigroupArr :: (Semigroup s') => Semigroup (s -> s')
869
976
870`(++)` is an alias for `(<>)`.
977`(++)` is an alias for `(<>)`.
871
978
979+#### `Bits`
980+
981+``` purescript
982+class Bits b where
983+ (.&.) :: b -> b -> b
984+ (.|.) :: b -> b -> b
985+ (.^.) :: b -> b -> b
986+ shl :: b -> Number -> b
987+ shr :: b -> Number -> b
988+ zshr :: b -> Number -> b
989+ complement :: b -> b
990+```
991+
992+The `Bits` type class identifies types which support bitwise operations.
993+
994+#### `bitsNumber`
995+
996+``` purescript
997+instance bitsNumber :: Bits Number
998+```
999+
1000+
872
1001
873## Module Data.Function
1002## Module Data.Function
874
1003
@@ -1243,7 +1372,7 @@ untilE :: forall e. Eff e Boolean -> Eff e Unit
1243
1372
1244Loop until a condition becomes `true`.
1373Loop until a condition becomes `true`.
1245
1374
1246−`untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
1375+`untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
1247until its return value is `true`.
1376until its return value is `true`.
1248
1377
1249#### `whileE`
1378#### `whileE`
@@ -1254,7 +1383,7 @@ whileE :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1254
1383
1255Loop while a condition is `true`.
1384Loop while a condition is `true`.
1256
1385
1257−`whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
1386+`whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
1258`true`, it runs the effectful computation `m` and loops. If not, the computation ends.
1387`true`, it runs the effectful computation `m` and loops. If not, the computation ends.
1259
1388
1260#### `forE`
1389#### `forE`
prelude/prelude.purs+178−86
@@ -22,9 +22,13 @@ module Prelude
22 , Num
22 , Num
23 , Eq, (==), (/=)
23 , Eq, (==), (/=)
24 , Ord, Ordering(..), compare, (<), (>), (<=), (>=)
24 , Ord, Ordering(..), compare, (<), (>), (<=), (>=)
25+ , Bounded, top, bottom
26+ , Lattice, sup, inf, (||), (&&)
27+ , BoundedLattice
28+ , ComplementedLattice, not
29+ , DistributiveLattice
30+ , BooleanAlgebra
25 , Bits, (.&.), (.|.), (.^.), shl, shr, zshr, complement
31 , Bits, (.&.), (.|.), (.^.), shl, shr, zshr, complement
26− , BoolLike, (&&), (||)
27− , not
28 , Semigroup, (<>), (++)
32 , Semigroup, (<>), (++)
29 , Unit(..), unit
33 , Unit(..), unit
30 ) where
34 ) where
@@ -108,16 +112,16 @@ module Prelude
108 infixr 0 $
112 infixr 0 $
109 infixl 0 #
113 infixl 0 #
110
114
111− -- | Applies a function to its argument
115+ -- | Applies a function to its argument.
112 -- |
116 -- |
113 -- | ```purescript
117 -- | ```purescript
114− -- | length $ groupBy productCategory $ filter isInStock products
118+ -- | length $ groupBy productCategory $ filter isInStock $ products
115 -- | ```
119 -- | ```
116 -- |
120 -- |
117 -- | is equivalent to
121 -- | is equivalent to
118 -- |
122 -- |
119 -- | ```purescript
123 -- | ```purescript
120− -- | length (groupBy productCategory (filter isInStock (products)))
124+ -- | length (groupBy productCategory (filter isInStock products))
121 -- | ```
125 -- | ```
122 -- |
126 -- |
123 -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
127 -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
@@ -126,16 +130,16 @@ module Prelude
126 ($) :: forall a b. (a -> b) -> a -> b
130 ($) :: forall a b. (a -> b) -> a -> b
127 ($) f x = f x
131 ($) f x = f x
128
132
129− -- | Applies a function to its argument
133+ -- | Applies an argument to a function.
130 -- |
134 -- |
131 -- | ```purescript
135 -- | ```purescript
132− -- | products # groupBy productCategory # filter isInStock # length
136+ -- | products # filter isInStock # groupBy productCategory # length
133 -- | ```
137 -- | ```
134 -- |
138 -- |
135 -- | is equivalent to
139 -- | is equivalent to
136 -- |
140 -- |
137 -- | ```purescript
141 -- | ```purescript
138− -- | length (filter isInStock (groupBy productCategory (products)))
142+ -- | length (groupBy productCategory (filter isInStock products))
139 -- | ```
143 -- | ```
140 -- |
144 -- |
141 -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
145 -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
@@ -702,6 +706,172 @@ module Prelude
702 EQ -> compare xs ys
706 EQ -> compare xs ys
703 other -> other
707 other -> other
704
708
709+ -- | The `Bounded` type class represents types that are finite partially
710+ -- | ordered sets.
711+ -- |
712+ -- | Instances should satisfy the following law in addition to the `Ord` laws:
713+ -- |
714+ -- | - Ordering: `bottom <= a <= top`
715+ class (Ord a) <= Bounded a where
716+ top :: a
717+ bottom :: a
718+
719+ instance boundedBoolean :: Bounded Boolean where
720+ top = true
721+ bottom = false
722+
723+ -- | The `Lattice` type class represents types that are partially ordered
724+ -- | sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
725+ -- |
726+ -- | Instances should satisfy the following laws in addition to the `Ord`
727+ -- | laws:
728+ -- |
729+ -- | - Associativity:
730+ -- | - `a || (b || c) = (a || b) || c`
731+ -- | - `a && (b && c) = (a && b) && c`
732+ -- | - Commutativity:
733+ -- | - `a || b = b || a`
734+ -- | - `a && b = b && a`
735+ -- | - Absorption:
736+ -- | - `a || (a && b) = a`
737+ -- | - `a && (a || b) = a`
738+ -- | - Idempotent:
739+ -- | - `a || a = a`
740+ -- | - `a && a = a`
741+ class (Ord a) <= Lattice a where
742+ sup :: a -> a -> a
743+ inf :: a -> a -> a
744+
745+ instance latticeBoolean :: Lattice Boolean where
746+ sup = boolOr
747+ inf = boolAnd
748+
749+ -- | The `BoundedLattice` type class represents types that are finite
750+ -- | lattices.
751+ -- |
752+ -- | Instances should satisfy the following law in addition to the `Lattice`
753+ -- | and `Bounded` laws:
754+ -- |
755+ -- | - Identity:
756+ -- | - `a || bottom = a`
757+ -- | - `a && top = a`
758+ -- | - Annihiliation:
759+ -- | - `a || top = top`
760+ -- | - `a && bottom = bottom`
761+ class (Bounded a, Lattice a) <= BoundedLattice a
762+
763+ instance boundedLatticeBoolean :: BoundedLattice Boolean
764+
765+ -- | The `ComplementedLattice` type class represents types that are lattices
766+ -- | where every member is also uniquely complemented.
767+ -- |
768+ -- | Instances should satisfy the following law in addition to the
769+ -- | `BoundedLattice` laws:
770+ -- |
771+ -- | - Complemented:
772+ -- | - `not a || a == top`
773+ -- | - `not a && a == bottom`
774+ -- | - Double negation:
775+ -- | - `not <<< not == id`
776+ class (BoundedLattice a) <= ComplementedLattice a where
777+ not :: a -> a
778+
779+ instance complementedLatticeBoolean :: ComplementedLattice Boolean where
780+ not = boolNot
781+
782+ -- | The `DistributiveLattice` type class represents types that are lattices
783+ -- | where the `&&` and `||` distribute over each other.
784+ -- |
785+ -- | Instances should satisfy the following law in addition to the `Lattice`
786+ -- | laws:
787+ -- |
788+ -- | - Distributivity: `x && (y || z) = (x && y) || (x && z)`
789+ class (Lattice a) <= DistributiveLattice a
790+
791+ instance distributiveLatticeBoolean :: DistributiveLattice Boolean
792+
793+ -- | The `BooleanAlgebra` type class represents types that are Boolean
794+ -- | algebras, also known as Boolean lattices.
795+ -- |
796+ -- | Instances should satisfy the `ComplementedLattice` and
797+ -- | `DistributiveLattice` laws.
798+ class (ComplementedLattice a, DistributiveLattice a) <= BooleanAlgebra a
799+
800+ instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
801+
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
815+ """
816+ function boolAnd(b1) {
817+ return function(b2) {
818+ return b1 && b2;
819+ };
820+ }
821+ """ :: Boolean -> Boolean -> Boolean
822+
823+ foreign import boolOr
824+ """
825+ function boolOr(b1) {
826+ return function(b2) {
827+ return b1 || b2;
828+ };
829+ }
830+ """ :: Boolean -> Boolean -> Boolean
831+
832+ foreign import boolNot
833+ """
834+ function boolNot(b) {
835+ return !b;
836+ }
837+ """ :: Boolean -> Boolean
838+
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+
705 infixl 10 .&.
875 infixl 10 .&.
706 infixl 10 .|.
876 infixl 10 .|.
707 infixl 10 .^.
877 infixl 10 .^.
@@ -786,84 +956,6 @@ module Prelude
786 zshr = numZshr
956 zshr = numZshr
787 complement = numComplement
957 complement = numComplement
788
958
789− infixr 2 ||
790− infixr 3 &&
791−
792− -- | The `BoolLike` type class identifies types which support Boolean operations.
793− -- |
794− -- | `BoolLike` instances are required to satisfy the laws of a _Boolean algebra_.
795− -- |
796− class BoolLike b where
797− (&&) :: b -> b -> b
798− (||) :: b -> b -> b
799− not :: b -> b
800−
801− foreign import boolAnd
802− """
803− function boolAnd(b1) {
804− return function(b2) {
805− return b1 && b2;
806− };
807− }
808− """ :: Boolean -> Boolean -> Boolean
809−
810− foreign import boolOr
811− """
812− function boolOr(b1) {
813− return function(b2) {
814− return b1 || b2;
815− };
816− }
817− """ :: Boolean -> Boolean -> Boolean
818−
819− foreign import boolNot
820− """
821− function boolNot(b) {
822− return !b;
823− }
824− """ :: Boolean -> Boolean
825−
826− instance boolLikeBoolean :: BoolLike Boolean where
827− (&&) = boolAnd
828− (||) = boolOr
829− not = boolNot
830−
831− infixr 5 <>
832−
833− -- | The `Semigroup` type class identifies an associative operation on a type.
834− -- |
835− -- | `Semigroup` instances are required to satisfy the following law:
836− -- |
837− -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
838− -- |
839− -- | For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
840− class Semigroup a where
841− (<>) :: a -> a -> a
842−
843− foreign import concatString
844− """
845− function concatString(s1) {
846− return function(s2) {
847− return s1 + s2;
848− };
849− }
850− """ :: String -> String -> String
851−
852− instance semigroupUnit :: Semigroup Unit where
853− (<>) (Unit {}) (Unit {}) = Unit {}
854−
855− instance semigroupString :: Semigroup String where
856− (<>) = concatString
857−
858− instance semigroupArr :: (Semigroup s') => Semigroup (s -> s') where
859− (<>) f g = \x -> f x <> g x
860−
861− infixr 5 ++
862−
863− -- | `(++)` is an alias for `(<>)`.
864− (++) :: forall s. (Semigroup s) => s -> s -> s
865− (++) = (<>)
866−
867module Data.Function where
959module Data.Function where
868
960
869 -- | The `on` function is used to change the domain of a binary operator.
961 -- | The `on` function is used to change the domain of a binary operator.
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+7−3
@@ -86,6 +86,8 @@ inlineValues = everywhereOnJS convert
86 convert :: JS -> JS
86 convert :: JS -> JS
87 convert (JSApp fn [dict]) | isPreludeDict C.semiringNumber dict && isPreludeFn C.zero fn = JSNumericLiteral (Left 0)
87 convert (JSApp fn [dict]) | isPreludeDict C.semiringNumber dict && isPreludeFn C.zero fn = JSNumericLiteral (Left 0)
88 convert (JSApp fn [dict]) | isPreludeDict C.semiringNumber dict && isPreludeFn C.one fn = JSNumericLiteral (Left 1)
88 convert (JSApp fn [dict]) | isPreludeDict C.semiringNumber dict && isPreludeFn C.one fn = JSNumericLiteral (Left 1)
89+ convert (JSApp fn [dict]) | isPreludeDict C.boundedBoolean dict && isPreludeFn C.bottom fn = JSBooleanLiteral False
90+ convert (JSApp fn [dict]) | isPreludeDict C.boundedBoolean dict && isPreludeFn C.top fn = JSBooleanLiteral True
89 convert (JSApp (JSApp fn [x]) [y]) | isPreludeFn (C.%) fn = JSBinary Modulus x y
91 convert (JSApp (JSApp fn [x]) [y]) | isPreludeFn (C.%) fn = JSBinary Modulus x y
90 convert other = other
92 convert other = other
91
93
@@ -130,9 +132,11 @@ inlineCommonOperators = applyAll $
130 , binary C.bitsNumber (C..^.) BitwiseXor
132 , binary C.bitsNumber (C..^.) BitwiseXor
131 , unary C.bitsNumber C.complement BitwiseNot
133 , unary C.bitsNumber C.complement BitwiseNot
132
134
133− , binary C.boolLikeBoolean (C.&&) And
135+ , binary C.latticeBoolean (C.&&) And
134− , binary C.boolLikeBoolean (C.||) Or
136+ , binary C.latticeBoolean (C.||) Or
135− , unary C.boolLikeBoolean C.not Not
137+ , binaryFunction C.latticeBoolean C.inf And
138+ , binaryFunction C.latticeBoolean C.sup Or
139+ , unary C.complementedLatticeBoolean C.not Not
136 ] ++
140 ] ++
137 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
141 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
138 where
142 where
src/Language/PureScript/Constants.hs+20−2
@@ -103,6 +103,12 @@ complement = "complement"
103not :: String
103not :: String
104not = "not"
104not = "not"
105
105
106+sup :: String
107+sup = "sup"
108+
109+inf :: String
110+inf = "inf"
111+
106-- Prelude Values
112-- Prelude Values
107
113
108zero :: String
114zero :: String
@@ -111,6 +117,12 @@ zero = "zero"
111one :: String
117one :: String
112one = "one"
118one = "one"
113
119
120+bottom :: String
121+bottom = "bottom"
122+
123+top :: String
124+top = "top"
125+
114return :: String
126return :: String
115return = "return"
127return = "return"
116
128
@@ -196,8 +208,14 @@ eqBoolean = "eqBoolean"
196bitsNumber :: String
208bitsNumber :: String
197bitsNumber = "bitsNumber"
209bitsNumber = "bitsNumber"
198
210
199−boolLikeBoolean :: String
211+boundedBoolean :: String
200−boolLikeBoolean = "boolLikeBoolean"
212+boundedBoolean = "boundedBoolean"
213+
214+latticeBoolean :: String
215+latticeBoolean = "latticeBoolean"
216+
217+complementedLatticeBoolean :: String
218+complementedLatticeBoolean = "complementedLatticeBoolean"
201
219
202semigroupString :: String
220semigroupString :: String
203semigroupString = "semigroupString"
221semigroupString = "semigroupString"