@@ -21,11 +21,7 @@ module Prelude
2121 , Eq , eq , (==), (/=)
2222 , Ordering (..), Ord , compare , (<), (>), (<=), (>=)
2323 , Bounded , top , bottom
24- , Lattice , sup , inf , (||), (&&)
25- , BoundedLattice
26- , ComplementedLattice , not
27- , DistributiveLattice
28- , BooleanAlgebra
24+ , BooleanAlgebra , conj , disj , not
2925 , Show , show
3026 ) where
3127
@@ -729,118 +725,65 @@ instance boundedInt :: Bounded Int where
729725 top = 2147483647
730726 bottom = -2147483648
731727
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 .
734730-- |
735- -- | Instances should satisfy the following laws in addition to the `Ord `
731+ -- | Instances should satisfy the following laws in addition to the `Bounded `
736732-- | laws:
737733-- |
738- -- | - Supremum:
739- -- | - `a || b >= a`
740- -- | - `a || b >= b`
741- -- | - Infimum:
742- -- | - `a && b <= a`
743- -- | - `a && b <= b`
744734-- | - Associativity:
745735-- | - `a || (b || c) = (a || b) || c`
746736-- | - `a && (b && c) = (a && b) && c`
747737-- | - Commutativity:
748738-- | - `a || b = b || a`
749739-- | - `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`
753746-- | - Idempotent:
754747-- | - `a || a = a`
755748-- | - `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
759761
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
763766
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
767771
768772infixr 2 ||
769773infixr 3 &&
770774
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
774778
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
778782
779783foreign import boolOr :: Boolean -> Boolean -> Boolean
780784foreign 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-
820785foreign import boolNot :: Boolean -> Boolean
821786
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-
844787-- | The `Show` type class represents those types which can be converted into
845788-- | a human-readable `String` representation.
846789-- |
0 commit comments