lude

Haskell prelude alternative
git clone git://git.rr3.xyz/lude | git clone gits://git.rr3.xyz/lude
Log | Files | Refs | README | LICENSE

Bound.hs (1133B)


      1 module Lude.Order.Bound (
      2     BoundedBelow (..),
      3     BoundedAbove (..),
      4     Bounded,
      5 ) where
      6 
      7 import Data.Coerce
      8 import Numeric.Natural qualified as Base
      9 import Prelude qualified as Base
     10 
     11 import Lude.Haskell
     12 import Lude.Order.Partial
     13 
     14 --------------------------------------------------------------------------------
     15 
     16 type BoundedBelow :: forall {r :: Repr}. Type# r -> Constraint
     17 class (PartiallyOrdered a) => BoundedBelow a where
     18     bot :: Lev a
     19 
     20 type BoundedAbove :: forall {r :: Repr}. Type# r -> Constraint
     21 class (PartiallyOrdered a) => BoundedAbove a where
     22     top :: Lev a
     23 
     24 type Bounded :: forall {r :: Repr}. Type# r -> Constraint
     25 class (BoundedBelow a, BoundedAbove a) => Bounded a
     26 instance (BoundedBelow a, BoundedAbove a) => Bounded a
     27 
     28 --------------------------------------------------------------------------------
     29 -- Interop
     30 
     31 instance (Base.Ord a, Base.Bounded a) => BoundedBelow (BaseInterop a) where bot = coerce Base.minBound
     32 instance (Base.Ord a, Base.Bounded a) => BoundedAbove (BaseInterop a) where top = coerce Base.maxBound
     33 
     34 instance BoundedBelow Base.Natural where bot = 0 where fromInteger = Base.fromInteger