Type-level Arithmetic
Digit
class IsDigit (d :: Symbol)
- type class constraint for
Symbol
encoding of type-level digits d \in [0-9]
- type class constraint for
class IsDigitPred (d :: Symbol) (b :: Bool.Boolean) | d -> b
- type-level predicate for
IsDigit
- type-level predicate for
class Compare (x :: Symbol) (y :: Symbol) (o :: Ord.Ordering) | x y -> o
- comparison of two Digits
- can be treated as a type-level instance of
compare
underOrd
type classinstance ordDigit :: Ord Digit where compare :: Digit -> Digit -> Ordering
class Add (x :: Symbol) (y :: Symbol) (carry :: Symbol) (z :: Symbol) | x y -> carry z
- addition of two Digits
x, y, z \in [0-9]
carry \in {0, 1}
- one dependency of
class Nat.Add
andclass Int.Add
- can be treated as a type-level instance of
add
underSemiring
type class, if without carrying digitinstance semiringDigit :: Semiring Digit where add :: Digit -> Digit -> Digit
- addition of two Digits
class Minus (x :: Symbol) (y :: Symbol) (carry :: Symbol) (z :: Symbol) | x y -> carry z
- subtraction of two Digits
x, y, z \in [0-9]
carry \in {0, 1}
1
denotes-1
for simplicity
- one dependency of
class Int.Minus
- can be treated as a type-level instance of
sub
underRing
type class, if without carrying digit
- subtraction of two Digits
IsNat
class IsNat (n :: Symbol)
- type class constraint for
Symbol
encoding of type-level natural numbers
- type class constraint for
class IsNatPred (n :: Symbol) (b :: Bool.Boolean) | n -> b
- type-level predicate for
IsNat
- type-level predicate for
class Add (x :: Symbol) (y :: Symbol) (z :: Symbol) | x y -> z
- addition of two Nats
class Succ (pred :: Symbol) (succ :: Symbol) | pred -> succ
- successor operator for Nat
IsInt
class IsSign (sign :: Symbol)
- type class constraint for
Symbol
encoding of signs of numbers sign \in {"+", "-"}
- type class constraint for
class IsSignPred (sign :: Symbol) (b :: Bool.Boolean) | sign -> b
- type-level predicate for
IsSign
- type-level predicate for
class HasSignPred (num :: Symbol) (b :: Bool.Boolean) | num -> b
- type-level predicate to check whether a type-level integer has sign
- assumption:
num :: Symbol
is underclass IsInt
class IsInt (num :: Symbol)
- type class constraint for
Symbol
encoding of integers
- type class constraint for
class IsIntPred (num :: Symbol) (b :: Bool.Boolean) | num -> b
- type-level predicate for
IsInt
- type-level predicate for
class IsNegativePred (num :: Symbol) (b :: Bool.Boolean) | num -> b
- type-level predicate to check whether a type-level integer is negative
- assumption:
num :: Symbol
is underclass IsInt
- preprocessed by
class Normalize
, so-0
is not mapped to negative
class Inverse (x :: Symbol) (inv :: Symbol) | x -> inv
- addictive inverse of Int
class Compare (x :: Symbol) (y :: Symbol) (o :: Ord.Ordering) | x y -> o
- comparison of two Ints
class Add (x :: Symbol) (y :: Symbol) (z :: Symbol) | x y -> z
- addition of two Ints
class Minus (x :: Symbol) (y :: Symbol) (z :: Symbol) | x y -> z
- subtraction of two Ints
class Normalize (i :: Symbol) (o :: Symbol) | i -> o
- normalization step for
Symbol
encoding of type-level integers- remove positive sign (
+
)
- e.g.
+123
->123
- remove prefixing zeros
- e.g.
-0000
->-0
- remove negative sign of zero if exists
- e.g.
-0
->0
- remove positive sign (
- normalization step for
class Pred (num :: Symbol) (pred :: Symbol) | num -> pred
- predecessor operator for Int