lude

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

Total.hs (1286B)


      1 module Lude.Order.Total (
      2     Ordering (..),
      3     (==),
      4     (/=),
      5     (≠),
      6     (<),
      7     (<=),
      8     (≤),
      9     (>=),
     10     (≥),
     11     (>),
     12     --
     13     TotallyOrdered (..),
     14     min,
     15     max,
     16 ) where
     17 
     18 import Data.Coerce
     19 import Numeric.Natural qualified as Base
     20 import Prelude qualified as Base
     21 
     22 import Lude.Equivalence
     23 import Lude.Function
     24 import Lude.Haskell
     25 import Lude.Maybe
     26 import Lude.Order.Lattice
     27 import Lude.Order.Partial
     28 
     29 --------------------------------------------------------------------------------
     30 
     31 type TotallyOrdered :: forall {r :: Repr}. Type# r -> Constraint
     32 class (Latticed a) => TotallyOrdered (a :: Type# r) where
     33     {-# MINIMAL #-}
     34 
     35     cmp :: a -> a -> Ordering
     36     default cmp :: (Functional# r) => a -> a -> Ordering
     37     cmp = unsafe_fromJust .*# pcmp
     38 
     39 min, max :: forall {r :: Repr} (a :: Type# r). (TotallyOrdered a) => Biendo a
     40 min = glb
     41 max = lub
     42 
     43 --------------------------------------------------------------------------------
     44 -- Interop
     45 
     46 instance (Base.Ord a) => TotallyOrdered (BaseInterop a) where
     47     cmp = coerce Base.compare
     48 
     49 deriving via BaseInterop Base.Natural instance TotallyOrdered Base.Natural
     50 deriving via BaseInterop Base.Integer instance TotallyOrdered Base.Integer
     51 deriving via BaseInterop Base.Rational instance TotallyOrdered Base.Rational