aboutsummaryrefslogtreecommitdiff
path: root/src/CHAD/Data.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2026-05-25 14:08:07 +0200
committerTom Smeding <tom@tomsmeding.com>2026-05-25 14:08:07 +0200
commitac13ffebefb22ec45e29e7f4bb6d53fa46cf6475 (patch)
treea4edfb35804ce46dcf683c35b5988cb003afb218 /src/CHAD/Data.hs
parentf5b1b405fa4ba63bdffe0f2998f655f0b06534bf (diff)
Up 'some' to 1.1HEADmaster
Diffstat (limited to 'src/CHAD/Data.hs')
-rw-r--r--src/CHAD/Data.hs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/CHAD/Data.hs b/src/CHAD/Data.hs
index 8c7605c..68b2554 100644
--- a/src/CHAD/Data.hs
+++ b/src/CHAD/Data.hs
@@ -8,11 +8,13 @@
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
-module CHAD.Data (module CHAD.Data, (:~:)(Refl), If) where
+module CHAD.Data (module CHAD.Data, (:~:)(Refl), If, EqP(eqp), OrdP(comparep)) where
+import Data.EqP
import Data.Functor.Product
import Data.GADT.Compare
import Data.GADT.Show
+import Data.OrdP
import Data.Some
import Data.Type.Bool (If)
import Data.Type.Equality
@@ -86,6 +88,11 @@ instance TestEquality SNat where testEquality = geq
instance GEq SNat where geq = defaultGeq
instance GShow SNat where gshowsPrec = defaultGshowsPrec
+instance Eq (SNat n) where _ == _ = True
+instance Ord (SNat n) where compare _ _ = EQ
+instance EqP SNat where eqp = eqpFromGEq
+instance OrdP SNat where comparep = comparepFromGCompare
+
fromSNat :: SNat n -> Int
fromSNat SZ = 0
fromSNat (SS n) = succ (fromSNat n)
@@ -190,3 +197,12 @@ data SBool b where
SF :: SBool False
ST :: SBool True
deriving instance Show (SBool b)
+
+eqpFromGEq :: GEq f => f a -> f b -> Bool
+eqpFromGEq x y = case geq x y of
+ Just Refl -> True
+ Nothing -> False
+
+comparepFromGCompare :: GCompare f => f a -> f b -> Ordering
+comparepFromGCompare x y = case gcompare x y of
+ GEQ -> EQ ; GLT -> LT ; GGT -> GT