Lattice.hs (2185B)
1 module Lude.Order.Lattice ( 2 GlbLatticed (..), 3 LubLatticed (..), 4 Latticed, 5 BoundedGlbLatticed, 6 BoundedLubLatticed, 7 BoundedLatticed, 8 ) where 9 10 import Data.Coerce 11 import Numeric.Natural qualified as Base 12 import Prelude qualified as Base 13 14 import Lude.Haskell 15 import Lude.Order.Bound 16 import Lude.Order.Partial 17 18 -- TODO: Infix operators for glb and lub? 19 20 -------------------------------------------------------------------------------- 21 22 type GlbLatticed :: forall {r :: Repr}. Type# r -> Constraint 23 class (PartiallyOrdered a) => GlbLatticed a where 24 glb :: Biendo a 25 26 type LubLatticed :: forall {r :: Repr}. Type# r -> Constraint 27 class (PartiallyOrdered a) => LubLatticed a where 28 lub :: Biendo a 29 30 type Latticed :: forall {r :: Repr}. Type# r -> Constraint 31 class (GlbLatticed a, LubLatticed a) => Latticed a 32 instance (GlbLatticed a, LubLatticed a) => Latticed a 33 34 type BoundedGlbLatticed :: forall {r :: Repr}. Type# r -> Constraint 35 class (BoundedAbove a, GlbLatticed a) => BoundedGlbLatticed a 36 instance (BoundedAbove a, GlbLatticed a) => BoundedGlbLatticed a 37 38 type BoundedLubLatticed :: forall {r :: Repr}. Type# r -> Constraint 39 class (BoundedBelow a, LubLatticed a) => BoundedLubLatticed a 40 instance (BoundedBelow a, LubLatticed a) => BoundedLubLatticed a 41 42 type BoundedLatticed :: forall {r :: Repr}. Type# r -> Constraint 43 class (BoundedGlbLatticed a, BoundedLubLatticed a) => BoundedLatticed a 44 instance (BoundedGlbLatticed a, BoundedLubLatticed a) => BoundedLatticed a 45 46 -------------------------------------------------------------------------------- 47 -- Interop 48 49 instance (Base.Ord a) => GlbLatticed (BaseInterop a) where glb = coerce Base.min 50 instance (Base.Ord a) => LubLatticed (BaseInterop a) where lub = coerce Base.max 51 52 deriving via BaseInterop Base.Natural instance GlbLatticed Base.Natural 53 deriving via BaseInterop Base.Natural instance LubLatticed Base.Natural 54 deriving via BaseInterop Base.Integer instance GlbLatticed Base.Integer 55 deriving via BaseInterop Base.Integer instance LubLatticed Base.Integer 56 deriving via BaseInterop Base.Rational instance GlbLatticed Base.Rational 57 deriving via BaseInterop Base.Rational instance LubLatticed Base.Rational