Copyright | (c) L. S. Leary 2025 |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Data.Type.Ord.Axiomata
Description
Axiomata for easier use of Data.Type.Ord.
\(\newcommand{\ldot}{.\,\,}\)
Synopsis
- type (<) (a :: k) (b :: k) = Compare a b ~ 'LT
- type (==) (a :: k) (b :: k) = Compare a b ~ 'EQ
- type (>) (a :: k) (b :: k) = Compare a b ~ 'GT
- type (<=) (a :: k) (b :: k) = (a <=? b) ~ 'True
- type (/=) (a :: k) (b :: k) = OrdCond (Compare a b) 'True 'False 'True ~ 'True
- type (>=) (a :: k) (b :: k) = (a >=? b) ~ 'True
- class Equivalence e where
- class Equivalence o => TotalOrder o where
- type family Reflect (o :: Ordering) = (p :: Ordering) | p -> o where ...
- minTO :: forall o (a :: o) (b :: o). TotalOrder o => Sing o a -> Sing o b -> Sing o (Min a b)
- maxTO :: forall o (a :: o) (b :: o). TotalOrder o => Sing o a -> Sing o b -> Sing o (Max a b)
- defaultDecideEq :: forall o (a :: o) (b :: o). TotalOrder o => Sing o a -> Sing o b -> Either ((a :~: b) -> Void) (a :~: b)
- class TotalOrder o => BoundedBelow o where
- type LowerBound o = (l :: o) | l -> o
- lowerBound :: Sing o (LowerBound o)
- least :: forall (a :: o). Sing o a -> Proof (LowerBound o <= a)
- class TotalOrder o => BoundedAbove o where
- type UpperBound o = (u :: o) | u -> o
- upperBound :: Sing o (UpperBound o)
- greatest :: forall (a :: o). Sing o a -> Proof (a <= UpperBound o)
- type family Sing k = (s :: k -> Type) | s -> k
- type family Proof c = (r :: Type) | r -> c where ...
Relations
should give rise to an equivalence relation and a total ordering on Compare
@OO
.
In particular, we can define relations:
\[ \begin{align} a < b &\iff \mathtt{Compare} \, a \, b \sim \mathtt{LT} \\ a = b &\iff \mathtt{Compare} \, a \, b \sim \mathtt{EQ} \\ a > b &\iff \mathtt{Compare} \, a \, b \sim \mathtt{GT} \\ a \leq b &\iff a < b \lor a = b \\ a \neq b &\iff a < b \lor a > b \\ a \geq b &\iff a = b \lor a > b \end{align} \]
These aren't consistent by construction, however—that's why we need axiomata.
N.B. We use and provide fixed versions of these relations from Data.Type.Ord as per #26190.
Axiomata
Equivalence
class Equivalence e where Source #
Eq
for
with Sing
e
.
Due to the inclusion of Compare
@esub
, symEq
and transEq
are demoted to lemmata.
Methods
Decidability of equivalence.
\[ \forall a, b \ldot a = b \lor a \neq b \]
Since refl
and sub
make them interchangeable, however, we actually use regular type equality for better ergonomics:
\[ \forall a, b \ldot a \sim b \lor a \not\sim b \]
Reflexivity of equivalence.
\[ \forall a \ldot a = a \]
Can also be read as:
\[ \forall a, b \ldot a \sim b \implies a = b \]
The other direction of sub
.
Substitutability: if two types are equivalent, one can be substituted for the other.
\[ \forall a, b \ldot a = b \implies a \sim b \]
The other direction of refl
.
Instances
Equivalence Nat Source # | |
Defined in Data.Type.Ord.Axiomata | |
Equivalence Char Source # | |
Defined in Data.Type.Ord.Axiomata | |
Equivalence Symbol Source # | |
Defined in Data.Type.Ord.Axiomata Methods (=?) :: forall (a :: Symbol) (b :: Symbol). Sing Symbol a -> Sing Symbol b -> Either ((a :~: b) -> Void) (a :~: b) Source # refl :: forall (a :: Symbol). Sing Symbol a -> Proof (a == a) Source # sub :: forall (a :: Symbol) (b :: Symbol). a == b => Sing Symbol a -> Sing Symbol b -> a :~: b Source # |
Total Order
class Equivalence o => TotalOrder o where Source #
Methods
Decidable connectivity of ordering.
\[ \forall a, b \ldot a < b \lor a = b \lor a > b \]
Anti-symmetry of ordering.
\[ \forall a, b \ldot a < b \iff b > a \]
Arguments
:: forall (a :: o) (b :: o) (c :: o). (a <= b, b <= c) | |
=> Sing o a | |
-> Sing o b | |
-> Sing o c | |
-> Proof (a <= c) |
Transitivity of \( \leq \).
\[ \forall a, b, c \ldot a \leq b \land b \leq c \implies a \leq c \]
Instances
type family Reflect (o :: Ordering) = (p :: Ordering) | p -> o where ... Source #
Reflect
an Ordering
(to express anti-symmetry).
minTO :: forall o (a :: o) (b :: o). TotalOrder o => Sing o a -> Sing o b -> Sing o (Min a b) Source #
The minimum of two totally-ordered singletons.
maxTO :: forall o (a :: o) (b :: o). TotalOrder o => Sing o a -> Sing o b -> Sing o (Max a b) Source #
The maximum of two totally-ordered singletons.
Bounding
class TotalOrder o => BoundedBelow o where Source #
TotalOrder
s with LowerBound
s.
Associated Types
type LowerBound o = (l :: o) | l -> o Source #
Methods
lowerBound :: Sing o (LowerBound o) Source #
Existence of a lower bound \( b_l \).
least :: forall (a :: o). Sing o a -> Proof (LowerBound o <= a) Source #
\( b_l \) is the least
element of o
.
\[ \forall a \ldot b_l \leq a \]
Instances
BoundedBelow Nat Source # | |||||
Defined in Data.Type.Ord.Axiomata Associated Types
| |||||
BoundedBelow Char Source # | |||||
Defined in Data.Type.Ord.Axiomata Associated Types
| |||||
BoundedBelow Symbol Source # | |||||
Defined in Data.Type.Ord.Axiomata Associated Types
|
class TotalOrder o => BoundedAbove o where Source #
TotalOrder
s with UpperBound
s.
Associated Types
type UpperBound o = (u :: o) | u -> o Source #
Methods
upperBound :: Sing o (UpperBound o) Source #
Existence of an upper bound \( b_u \).
greatest :: forall (a :: o). Sing o a -> Proof (a <= UpperBound o) Source #
\( b_u \) is the greatest
element of o
.
\[ \forall a \ldot a \leq b_u \]