| Copyright | (c) Alice Rixte 2025 |
|---|---|
| License | BSD 3 |
| Maintainer | alice.rixte@u-bordeaux.fr |
| Stability | unstable |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | None |
| Language | GHC2024 |
Data.Type.Int
Description
Type level integers.
Synopsis
- data Signed a
- type ZZ = Signed Nat
- type family CmpSigned (a :: Signed k) (b :: Signed k) :: Ordering where ...
- type family IsPos (a :: ZZ) :: Bool where ...
- type family FlipOrdering (o :: Ordering) :: Ordering where ...
- type family NormalizeInt (a :: ZZ) :: ZZ where ...
- type family Abs (a :: ZZ) :: Nat where ...
- type family Negate (a :: ZZ) :: ZZ where ...
- type family AddCmp (cmp :: Ordering) (a :: ZZ) (b :: ZZ) :: ZZ where ...
- type family Add (a :: ZZ) (b :: ZZ) :: ZZ where ...
- type family Sub (a :: ZZ) (b :: ZZ) :: ZZ where ...
- type family Mul (a :: ZZ) (b :: ZZ) :: ZZ where ...
- type family Pow (a :: ZZ) (n :: Nat) :: ZZ where ...
- class KnownInt (r :: ZZ) where
- data SZZ (z :: ZZ) where
- zero :: SZZ ('Zero :: Signed Nat)
- pos :: forall (n :: Nat). KnownNat n => SZZ ('Pos n)
- pos1 :: SZZ ('Pos 1)
- pos2 :: SZZ ('Pos 2)
- pos3 :: SZZ ('Pos 3)
- pos4 :: SZZ ('Pos 4)
- neg :: forall (n :: Nat). KnownNat n => SZZ ('Neg n)
- neg1 :: SZZ ('Neg 1)
- neg2 :: SZZ ('Neg 2)
- neg3 :: SZZ ('Neg 3)
- neg4 :: SZZ ('Neg 4)
- fromSZZ :: forall (n :: ZZ). SZZ n -> Integer
- withSomeSZZ :: Integer -> (forall (n :: ZZ). SZZ n -> r) -> r
- withKnownInt :: forall (n :: ZZ) r. SZZ n -> (KnownInt n => r) -> r
Documentation
Add a sign to any type
Type integers
ZZ represents the mathematical font for the set of integers
type family CmpSigned (a :: Signed k) (b :: Signed k) :: Ordering where ... Source #
Compare Signed kinds when those kinds are comparable.
Equations
| CmpSigned ('Neg a :: Signed k) ('Neg b :: Signed k) = FlipOrdering (Compare a b) | |
| CmpSigned ('Neg a :: Signed k) (b :: Signed k) = 'LT | |
| CmpSigned ('Zero :: Signed k) ('Neg a :: Signed k) = 'GT | |
| CmpSigned ('Zero :: Signed k) ('Zero :: Signed k) = 'EQ | |
| CmpSigned ('Zero :: Signed k) ('Pos a :: Signed k) = 'GT | |
| CmpSigned ('Pos a :: Signed k) ('Pos b :: Signed k) = Compare a b | |
| CmpSigned ('Pos a :: Signed k) (b :: Signed k) = 'GT |
type family FlipOrdering (o :: Ordering) :: Ordering where ... Source #
Reverse the order of an Ordering
This should be declared in to Data.Type.Ord in base
Equations
| FlipOrdering 'LT = 'GT | |
| FlipOrdering 'EQ = 'EQ | |
| FlipOrdering 'GT = 'LT |
type family NormalizeInt (a :: ZZ) :: ZZ where ... Source #
Always use Zero instead of Pos 0 or Neg 0.
Equations
| NormalizeInt ('Pos 0) = 'Zero :: Signed Nat | |
| NormalizeInt ('Neg 0) = 'Zero :: Signed Nat | |
| NormalizeInt n = n |
type family AddCmp (cmp :: Ordering) (a :: ZZ) (b :: ZZ) :: ZZ where ... Source #
Utility family for Add
Equations
| AddCmp _1 a ('Zero :: Signed Nat) = a | |
| AddCmp _1 ('Zero :: Signed Nat) b = b | |
| AddCmp _1 ('Pos a) ('Pos b) = 'Pos (a + b) | |
| AddCmp _1 ('Neg a) ('Neg b) = 'Neg (a + b) | |
| AddCmp 'EQ _1 _2 = 'Zero :: Signed Nat | |
| AddCmp 'LT ('Pos a) ('Neg b) = 'Neg (b - a) | |
| AddCmp 'GT ('Pos a) ('Neg b) = 'Pos (a - b) | |
| AddCmp 'LT ('Neg a) ('Pos b) = 'Pos (b - a) | |
| AddCmp 'GT ('Neg a) ('Pos b) = 'Neg (a - b) |
class KnownInt (r :: ZZ) where Source #
Gives the integer associated to a type-level integer.
pos :: forall (n :: Nat). KnownNat n => SZZ ('Pos n) Source #
Singleton for positive integers.
>>>:t pos @3pos @3 :: KnownNat 3 => SZZ ('Pos 3)
neg :: forall (n :: Nat). KnownNat n => SZZ ('Neg n) Source #
Singleton for negative integers.
>>>:t neg @3neg @3 :: KnownNat 3 => SZZ ('Neg 3)
fromSZZ :: forall (n :: ZZ). SZZ n -> Integer Source #
Return the Integer corresponding to n in an SZZ n value.