Copyright | (c) L. S. Leary 2025 |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Data.Type.Ord.Axiomata
Description
Axiomata & lemmata for easier use of Data.Type.Ord.
\[ \newcommand{\colon}{ \! : } \]
Synopsis
- type family Sing k = (s :: k -> Type) | s -> k
- 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 -> (LowerBound o <=? a) :~: 'True
- 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 -> (a <=? UpperBound o) :~: 'True
- sym :: forall e (a :: e) (b :: e). (Equivalence e, Compare a b ~ 'EQ) => Sing e a -> Sing e b -> Compare b a :~: 'EQ
- transEq :: forall e (a :: e) (b :: e) (c :: e). (Equivalence e, Compare a b ~ 'EQ, Compare b c ~ 'EQ) => Sing e a -> Sing e b -> Sing e c -> Compare a c :~: 'EQ
- minDefl1 :: forall o (a :: o) (b :: o). TotalOrder o => Sing o a -> Sing o b -> (Min a b <=? a) :~: 'True
- minDefl2 :: forall o (a :: o) (b :: o). TotalOrder o => Sing o a -> Sing o b -> (Min a b <=? b) :~: 'True
- minMono :: forall o (a :: o) (c :: o) (b :: o) (d :: o). (TotalOrder o, a <= c, b <= d) => Sing o a -> Sing o b -> Sing o c -> Sing o d -> (Min a b <=? Min c d) :~: 'True
- maxInfl1 :: forall o (a :: o) (b :: o). TotalOrder o => Sing o a -> Sing o b -> (a <=? Max a b) :~: 'True
- maxInfl2 :: forall o (a :: o) (b :: o). TotalOrder o => Sing o a -> Sing o b -> (b <=? Max a b) :~: 'True
- maxMono :: forall o (a :: o) (c :: o) (b :: o) (d :: o). (TotalOrder o, a <= c, b <= d) => Sing o a -> Sing o b -> Sing o c -> Sing o d -> (Max a b <=? Max c d) :~: 'True
Sing
type family Sing k = (s :: k -> Type) | s -> k Source #
Maps kinds to their corresponding singleton type constructors.
Axiomata
should give rise to an equivalence relation and a total ordering on Compare
@OO
.
In particular, we can define:
\[ \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 \geq b &\iff a > b \lor a = b \end{align} \]
These aren't consistent by construction, however—we need more axiomata.
Equivalence
class Equivalence e where Source #
Methods
Decidability of equivalence.
\[ \forall a, b \colon 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 \colon a \sim b \lor a \not\sim b \]
Reflexivity of equivalence.
\[ \forall a \colon a = a \]
Can also be read as:
\[ \forall a, b \colon 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 \colon 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 -> Compare a a :~: 'EQ Source # sub :: forall (a :: Symbol) (b :: Symbol). Compare a b ~ 'EQ => 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 \colon a \lt b \lor a = b \lor a \gt b \]
Anti-symmetry of ordering.
\[ \forall a, b \colon a \leq b \iff b \geq a \]
Arguments
:: forall (a :: o) (b :: o) (c :: o). (a <= b, b <= c) | |
=> Sing o a | |
-> Sing o b | |
-> Sing o c | |
-> (a <=? c) :~: 'True |
Transitivity of ordering.
\[ \forall a, b, c \colon 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 -> (LowerBound o <=? a) :~: 'True Source #
\( b_l \) is the least
element of o
.
\[ \forall a \colon 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 -> (a <=? UpperBound o) :~: 'True Source #
\( b_u \) is the greatest
element of o
.
\[ \forall a \colon a \leq b_u \]
Lemmata
Equivalence
Arguments
:: forall e (a :: e) (b :: e). (Equivalence e, Compare a b ~ 'EQ) | |
=> Sing e a | |
-> Sing e b | |
-> Compare b a :~: 'EQ |
Symmetry of equivalence.
\[ \forall a, b \colon a = b \iff b = a \]
Arguments
:: forall e (a :: e) (b :: e) (c :: e). (Equivalence e, Compare a b ~ 'EQ, Compare b c ~ 'EQ) | |
=> Sing e a | |
-> Sing e b | |
-> Sing e c | |
-> Compare a c :~: 'EQ |
Transitivity of equivalence.
\[ \forall a, b, c \colon a = b \land b = c \implies a = c \]
Min
Arguments
:: forall o (a :: o) (b :: o). TotalOrder o | |
=> Sing o a | |
-> Sing o b | |
-> (Min a b <=? a) :~: 'True |
Min
is deflationary in its first argument.
\[ \mathrm{min} \, a \, b \leq a \]
Arguments
:: forall o (a :: o) (b :: o). TotalOrder o | |
=> Sing o a | |
-> Sing o b | |
-> (Min a b <=? b) :~: 'True |
Min
is deflationary in its second argument.
\[ \mathrm{min} \, a \, b \leq b \]
Arguments
:: forall o (a :: o) (c :: o) (b :: o) (d :: o). (TotalOrder o, a <= c, b <= d) | |
=> Sing o a | |
-> Sing o b | |
-> Sing o c | |
-> Sing o d | |
-> (Min a b <=? Min c d) :~: 'True |
Min
is monotonic in both arguments.
\[ a \leq c \land b \leq d \implies \mathrm{min} \, a \, b \leq \mathrm{min} \, c \, d \]
Max
Arguments
:: forall o (a :: o) (b :: o). TotalOrder o | |
=> Sing o a | |
-> Sing o b | |
-> (a <=? Max a b) :~: 'True |
Max
is inflationary in its first argument.
\[ a \leq \mathrm{max} \, a \, b \]
Arguments
:: forall o (a :: o) (b :: o). TotalOrder o | |
=> Sing o a | |
-> Sing o b | |
-> (b <=? Max a b) :~: 'True |
Max
is inflationary in its second argument.
\[ b \leq \mathrm{max} \, a \, b \]