@@ -21,11 +21,7 @@ module Prelude
21
21
, Eq , eq , (==), (/=)
22
22
, Ordering (..), Ord , compare , (<), (>), (<=), (>=)
23
23
, Bounded , top , bottom
24
- , Lattice , sup , inf , (||), (&&)
25
- , BoundedLattice
26
- , ComplementedLattice , not
27
- , DistributiveLattice
28
- , BooleanAlgebra
24
+ , BooleanAlgebra , conj , disj , not
29
25
, Show , show
30
26
) where
31
27
@@ -729,118 +725,65 @@ instance boundedInt :: Bounded Int where
729
725
top = 2147483647
730
726
bottom = -2147483648
731
727
732
- -- | The `Lattice ` type class represents types that are partially ordered
733
- -- | sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`) .
728
+ -- | The `BooleanAlgebra ` type class represents types that behave like boolean
729
+ -- | values .
734
730
-- |
735
- -- | Instances should satisfy the following laws in addition to the `Ord `
731
+ -- | Instances should satisfy the following laws in addition to the `Bounded `
736
732
-- | laws:
737
733
-- |
738
- -- | - Supremum:
739
- -- | - `a || b >= a`
740
- -- | - `a || b >= b`
741
- -- | - Infimum:
742
- -- | - `a && b <= a`
743
- -- | - `a && b <= b`
744
734
-- | - Associativity:
745
735
-- | - `a || (b || c) = (a || b) || c`
746
736
-- | - `a && (b && c) = (a && b) && c`
747
737
-- | - Commutativity:
748
738
-- | - `a || b = b || a`
749
739
-- | - `a && b = b && a`
750
- -- | - Absorption:
751
- -- | - `a || (a && b) = a`
752
- -- | - `a && (a || b) = a`
740
+ -- | - Distributivity:
741
+ -- | - `a && (b || c) = (a && b) || (a && c)`
742
+ -- | - `a || (b && c) = (a || b) && (a || c)`
743
+ -- | - Identity:
744
+ -- | - `a || bottom = a`
745
+ -- | - `a && top = a`
753
746
-- | - Idempotent:
754
747
-- | - `a || a = a`
755
748
-- | - `a && a = a`
756
- class (Ord a ) <= Lattice a where
757
- sup :: a -> a -> a
758
- inf :: a -> a -> a
749
+ -- | - Absorption:
750
+ -- | - `a || (a && b) = a`
751
+ -- | - `a && (a || b) = a`
752
+ -- | - Annhiliation:
753
+ -- | - `a || top = top`
754
+ -- | - Complementation:
755
+ -- | - `a && not a = bottom`
756
+ -- | - `a || not a = top`
757
+ class (Bounded a ) <= BooleanAlgebra a where
758
+ conj :: a -> a -> a
759
+ disj :: a -> a -> a
760
+ not :: a -> a
759
761
760
- instance latticeBoolean :: Lattice Boolean where
761
- sup = boolOr
762
- inf = boolAnd
762
+ instance booleanAlgebraBoolean :: BooleanAlgebra Boolean where
763
+ conj = boolAnd
764
+ disj = boolOr
765
+ not = boolNot
763
766
764
- instance latticeUnit :: Lattice Unit where
765
- sup _ _ = unit
766
- inf _ _ = unit
767
+ instance booleanAlgebraUnit :: BooleanAlgebra Unit where
768
+ conj _ _ = unit
769
+ disj _ _ = unit
770
+ not _ = unit
767
771
768
772
infixr 2 ||
769
773
infixr 3 &&
770
774
771
- -- | The `sup ` operator.
772
- (||) :: forall a . (Lattice a ) => a -> a -> a
773
- (||) = sup
775
+ -- | The `conj ` operator.
776
+ (||) :: forall a . (BooleanAlgebra a ) => a -> a -> a
777
+ (||) = conj
774
778
775
- -- | The `inf ` operator.
776
- (&&) :: forall a . (Lattice a ) => a -> a -> a
777
- (&&) = inf
779
+ -- | The `disj ` operator.
780
+ (&&) :: forall a . (BooleanAlgebra a ) => a -> a -> a
781
+ (&&) = disj
778
782
779
783
foreign import boolOr :: Boolean -> Boolean -> Boolean
780
784
foreign import boolAnd :: Boolean -> Boolean -> Boolean
781
-
782
- -- | The `BoundedLattice` type class represents types that are finite
783
- -- | lattices.
784
- -- |
785
- -- | Instances should satisfy the following law in addition to the `Lattice`
786
- -- | and `Bounded` laws:
787
- -- |
788
- -- | - Identity:
789
- -- | - `a || bottom = a`
790
- -- | - `a && top = a`
791
- -- | - Annihiliation:
792
- -- | - `a || top = top`
793
- -- | - `a && bottom = bottom`
794
- class (Bounded a , Lattice a ) <= BoundedLattice a
795
-
796
- instance boundedLatticeBoolean :: BoundedLattice Boolean
797
-
798
- instance boundedLatticeUnit :: BoundedLattice Unit
799
-
800
- -- | The `ComplementedLattice` type class represents types that are lattices
801
- -- | where every member is also uniquely complemented.
802
- -- |
803
- -- | Instances should satisfy the following law in addition to the
804
- -- | `BoundedLattice` laws:
805
- -- |
806
- -- | - Complemented:
807
- -- | - `not a || a == top`
808
- -- | - `not a && a == bottom`
809
- -- | - Double negation:
810
- -- | - `not <<< not == id`
811
- class (BoundedLattice a ) <= ComplementedLattice a where
812
- not :: a -> a
813
-
814
- instance complementedLatticeBoolean :: ComplementedLattice Boolean where
815
- not = boolNot
816
-
817
- instance complementedLatticeUnit :: ComplementedLattice Unit where
818
- not _ = unit
819
-
820
785
foreign import boolNot :: Boolean -> Boolean
821
786
822
- -- | The `DistributiveLattice` type class represents types that are lattices
823
- -- | where the `&&` and `||` distribute over each other.
824
- -- |
825
- -- | Instances should satisfy the following law in addition to the `Lattice`
826
- -- | laws:
827
- -- |
828
- -- | - Distributivity: `x && (y || z) = (x && y) || (x && z)`
829
- class (Lattice a ) <= DistributiveLattice a
830
-
831
- instance distributiveLatticeBoolean :: DistributiveLattice Boolean
832
- instance distributiveLatticeUnit :: DistributiveLattice Unit
833
-
834
- -- | The `BooleanAlgebra` type class represents types that are Boolean
835
- -- | algebras, also known as Boolean lattices.
836
- -- |
837
- -- | Instances should satisfy the `ComplementedLattice` and
838
- -- | `DistributiveLattice` laws.
839
- class (ComplementedLattice a , DistributiveLattice a ) <= BooleanAlgebra a
840
-
841
- instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
842
- instance booleanAlgebraUnit :: BooleanAlgebra Unit
843
-
844
787
-- | The `Show` type class represents those types which can be converted into
845
788
-- | a human-readable `String` representation.
846
789
-- |
0 commit comments