type-level-0.3.0: Type-level programming library

Copyright(c) 2008 Alfonso Acosta, Oleg Kiselyov, Wolfgang Jeltsch and KTH's SAM group
LicenseBSD-style (see the file LICENSE)
Maintaineralfonso.acosta@gmail.com
Stabilityexperimental
Portabilitynon-portable (MPTC, non-standard instances)
Safe HaskellNone
LanguageHaskell98

Data.TypeLevel.Num.Ops

Contents

Description

Type-level numerical operations and its value-level reflection functions.

Synopsis

Successor/Predecessor

class (Nat x, Pos y) => Succ x y | x -> y, y -> x Source

Successor type-level relation. Succ x y establishes that succ x = y.

Instances

(Pos y, IsZero y yz, DivMod10 x xi xl, Succ' xi xl yi yl yz, DivMod10 y yi yl) => Succ x y Source 

succ :: Succ x y => x -> y Source

value-level reflection function for the Succ type-level relation

class (Pos x, Nat y) => Pred x y | x -> y, y -> x Source

Predecessor type-level relation. Pred x y establishes that pred x = y.

Instances

Succ x y => Pred y x Source 

pred :: Pred x y => x -> y Source

value-level reflection function for the Pred type-level relation

Addition/Subtraction

class (Add' x y z, Add' y x z) => Add x y z | x y -> z, z x -> y, z y -> x Source

Addition type-level relation. Add x y z establishes that x + y = z.

Instances

(Add' x y z, Add' y x z) => Add x y z Source 

(+) :: Add x y z => x -> y -> z infixl 6 Source

value-level reflection function for the Add type-level relation

class Sub x y z | x y -> z, z x -> y, z y -> x Source

Subtraction type-level relation. Sub x y z establishes that x - y = z

Instances

Add x y z => Sub z y x Source 

(-) :: Sub x y z => x -> y -> z infixl 6 Source

value-level reflection function for the Sub type-level relation

Multiplication/Division

class (Nat x, Nat y, Nat z) => Mul x y z | x y -> z Source

Multiplication type-level relation. Mul x y z establishes that x * y = z. Note it isn't relational (i.e. its inverse cannot be used for division, however, even if it could, the resulting division would only work for zero-remainder divisions)

Instances

(Add z y z', Mul D8 y z) => Mul D9 y z' Source 
(Add z y z', Mul D7 y z) => Mul D8 y z' Source 
(Add z y z', Mul D6 y z) => Mul D7 y z' Source 
(Add z y z', Mul D5 y z) => Mul D6 y z' Source 
(Add z y z', Mul D4 y z) => Mul D5 y z' Source 
(Add z y z', Mul D3 y z) => Mul D4 y z' Source 
(Add z y z', Mul D2 y z) => Mul D3 y z' Source 
Add y y z => Mul D2 y z Source 
Nat y => Mul D1 y y Source 
Nat y => Mul D0 y D0 Source 
(Pos ((:*) xi xl), Nat y, Mul xi y z, Mul10 z z10, Mul xl y dy, Add dy z10 z') => Mul ((:*) xi xl) y z' Source 

(*) :: Mul x y z => x -> y -> z infixl 7 Source

value-level reflection function for the multiplication type-level relation

class Div x y z | x y -> z Source

Division type-level relation. Remainder-discarding version of DivMod. Note it is not relational (due to DivMod not being relational)

Instances

DivMod x y q r => Div x y q Source 

div :: Div x y z => x -> y -> z infixl 7 Source

value-level reflection function for the Div type-level relation

class Mod x y r | x y -> r Source

Remainder of division, type-level relation. Mod x y r establishes that r is the reminder of dividing x by y.

Instances

DivMod x y q r => Mod x y r Source 

mod :: Mod x y r => x -> y -> r infixl 7 Source

value-level reflection function for the Mod type-level relation

class (Nat x, Pos y) => DivMod x y q r | x y -> q r Source

Division and Remainder type-level relation. DivMod x y q r establishes that xy = q + ry Note it is not relational (i.e. its inverse cannot be used for multiplication).

Instances

(Pos y, Trich x y cmp, DivMod' x y q r cmp) => DivMod x y q r Source 

divMod :: DivMod x y q r => x -> y -> (q, r) Source

value-level reflection function for the DivMod type-level relation

class (Pos d, Nat x) => IsDivBy d x Source

Is-divisible-by type-level assertion. e.g IsDivBy d x establishes that x is divisible by d.

Instances

DivMod x d q D0 => IsDivBy d x Source 

isDivBy :: IsDivBy d x => d -> x Source

value-level reflection function for IsDivBy

Special efficiency cases

class (Nat x, Nat q) => Mul10 x q | x -> q, q -> x Source

Multiplication by 10 type-level relation (based on DivMod10). Mul10 x y establishes that 10 * x = y.

Instances

DivMod10 x q D0 => Mul10 q x Source 

mul10 :: Mul10 x q => x -> q Source

value-level reflection function for Mul10

class (Nat x, Nat q) => Div10 x q | x -> q Source

Division by 10 type-level relation (based on DivMod10)

Instances

DivMod10 x q r => Div10 x q Source 

div10 :: Div10 x q => x -> q Source

value-level reflection function for Mul10

class (Nat i, Nat x) => DivMod10 x i l | i l -> x, x -> i l Source

Division by 10 and Remainer type-level relation (similar to DivMod).

This operation is much faster than DivMod. Furthermore, it is the general, non-structural, constructor/deconstructor since it splits a decimal numeral into its initial digits and last digit. Thus, it allows to inspect the structure of a number and is normally used to create type-level operations.

Note that contrary to DivMod, DivMod10 is relational (it can be used to multiply by 10)

divMod10 :: DivMod10 x q r => x -> (q, r) Source

value-level reflection function for DivMod10

Exponientiation/Logarithm

class (Nat b, Nat e, Nat r) => ExpBase b e r | b e -> r Source

Exponentation type-level relation. ExpBase b e r establishes that b^e = r Note it is not relational (i.e. it cannot be used to express logarithms)

Instances

(Mul r b r', ExpBase b D8 r) => ExpBase b D9 r' Source 
(Mul r b r', ExpBase b D7 r) => ExpBase b D8 r' Source 
(Mul r b r', ExpBase b D6 r) => ExpBase b D7 r' Source 
(Mul r b r', ExpBase b D5 r) => ExpBase b D6 r' Source 
(Mul r b r', ExpBase b D4 r) => ExpBase b D5 r' Source 
(Mul r b r', ExpBase b D3 r) => ExpBase b D4 r' Source 
(Mul r b r', ExpBase b D2 r) => ExpBase b D3 r' Source 
Mul b b r => ExpBase b D2 r Source 
Nat b => ExpBase b D1 b Source 
Nat b => ExpBase b D0 D1 Source 
(Nat b, Pos ((:*) ei el), Nat r, Mul b r r', Pred ((:*) ei el) e', ExpBase b e' r) => ExpBase b ((:*) ei el) r' Source 

(^) :: ExpBase b e r => b -> e -> r infixr 8 Source

value-level reflection function for the ExpBase type-level relation

class (Pos b, b :>=: D2, Pos x, Nat e) => LogBase b x e | b x -> e Source

Instances

(Pos b, (:>=:) b D2, Pos x, Nat e, LogBaseF b x e f) => LogBase b x e Source 

logBase :: LogBaseF b x e f => b -> x -> e Source

value-level reflection function for LogBase

class (Pos b, b :>=: D2, Pos x, Nat e, Bool f) => LogBaseF b x e f | b x -> e f Source

Version of LogBase which also outputs if the logarithm calculated was exact. f indicates if the resulting logarithm has no fractional part (i.e. tells if the result provided is exact)

Instances

(Pos b, (:>=:) b D2, Pos x, Nat e, Bool f, Trich x b cmp, LogBaseF' b x e f cmp) => LogBaseF b x e f Source 

logBaseF :: LogBaseF b x e f => b -> x -> (e, f) Source

value-level reflection function for LogBaseF

class (Pos b, b :>=: D2, Pos x) => IsPowOf b x Source

Assert that a number (x) can be expressed as the power of another one (b) (i.e. the fractional part of log_base_b x = 0, or, in a different way, exists y . b^y = x).

Instances

(Pos b, (:>=:) b D2, Pos x, Trich x b cmp, IsPowOf' b x cmp) => IsPowOf b x Source 

isPowOf :: IsPowOf b x => b -> x -> () Source

Special efficiency cases

class (Nat x, Pos y) => Exp10 x y | x -> y, y -> x Source

Base-10 Exponentiation type-level relation

exp10 :: Exp10 x y => x -> y Source

value-level reflection function for Exp10

class (Pos x, Nat y) => Log10 x y | x -> y Source

Base-10 logarithm type-level relation Note it is not relational (cannot be used to express Exponentation to 10) However, it works with any positive numeral (not just powers of 10)

log10 :: Log10 x y => x -> y Source

value-level reflection function for Log10

Comparison assertions

General comparison assertion

class (Nat x, Nat y) => Trich x y r | x y -> r Source

Trichotomy type-level relation. 'Trich x y r' establishes the relation (r) between x and y. The obtained relation (r) Can be LT (if x is lower than y), EQ (if x equals y) or GT (if x is greater than y)

Instances

Trich D9 D9 EQ Source 
Trich D9 D8 GT Source 
Trich D9 D7 GT Source 
Trich D9 D6 GT Source 
Trich D9 D5 GT Source 
Trich D9 D4 GT Source 
Trich D9 D3 GT Source 
Trich D9 D2 GT Source 
Trich D9 D1 GT Source 
Trich D9 D0 GT Source 
Trich D8 D9 LT Source 
Trich D8 D8 EQ Source 
Trich D8 D7 GT Source 
Trich D8 D6 GT Source 
Trich D8 D5 GT Source 
Trich D8 D4 GT Source 
Trich D8 D3 GT Source 
Trich D8 D2 GT Source 
Trich D8 D1 GT Source 
Trich D8 D0 GT Source 
Trich D7 D9 LT Source 
Trich D7 D8 LT Source 
Trich D7 D7 EQ Source 
Trich D7 D6 GT Source 
Trich D7 D5 GT Source 
Trich D7 D4 GT Source 
Trich D7 D3 GT Source 
Trich D7 D2 GT Source 
Trich D7 D1 GT Source 
Trich D7 D0 GT Source 
Trich D6 D9 LT Source 
Trich D6 D8 LT Source 
Trich D6 D7 LT Source 
Trich D6 D6 EQ Source 
Trich D6 D5 GT Source 
Trich D6 D4 GT Source 
Trich D6 D3 GT Source 
Trich D6 D2 GT Source 
Trich D6 D1 GT Source 
Trich D6 D0 GT Source 
Trich D5 D9 LT Source 
Trich D5 D8 LT Source 
Trich D5 D7 LT Source 
Trich D5 D6 LT Source 
Trich D5 D5 EQ Source 
Trich D5 D4 GT Source 
Trich D5 D3 GT Source 
Trich D5 D2 GT Source 
Trich D5 D1 GT Source 
Trich D5 D0 GT Source 
Trich D4 D9 LT Source 
Trich D4 D8 LT Source 
Trich D4 D7 LT Source 
Trich D4 D6 LT Source 
Trich D4 D5 LT Source 
Trich D4 D4 EQ Source 
Trich D4 D3 GT Source 
Trich D4 D2 GT Source 
Trich D4 D1 GT Source 
Trich D4 D0 GT Source 
Trich D3 D9 LT Source 
Trich D3 D8 LT Source 
Trich D3 D7 LT Source 
Trich D3 D6 LT Source 
Trich D3 D5 LT Source 
Trich D3 D4 LT Source 
Trich D3 D3 EQ Source 
Trich D3 D2 GT Source 
Trich D3 D1 GT Source 
Trich D3 D0 GT Source 
Trich D2 D9 LT Source 
Trich D2 D8 LT Source 
Trich D2 D7 LT Source 
Trich D2 D6 LT Source 
Trich D2 D5 LT Source 
Trich D2 D4 LT Source 
Trich D2 D3 LT Source 
Trich D2 D2 EQ Source 
Trich D2 D1 GT Source 
Trich D2 D0 GT Source 
Trich D1 D9 LT Source 
Trich D1 D8 LT Source 
Trich D1 D7 LT Source 
Trich D1 D6 LT Source 
Trich D1 D5 LT Source 
Trich D1 D4 LT Source 
Trich D1 D3 LT Source 
Trich D1 D2 LT Source 
Trich D1 D1 EQ Source 
Trich D1 D0 GT Source 
Trich D0 D9 LT Source 
Trich D0 D8 LT Source 
Trich D0 D7 LT Source 
Trich D0 D6 LT Source 
Trich D0 D5 LT Source 
Trich D0 D4 LT Source 
Trich D0 D3 LT Source 
Trich D0 D2 LT Source 
Trich D0 D1 LT Source 
Trich D0 D0 EQ Source 
Pos ((:*) yi yl) => Trich D9 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D8 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D7 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D6 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D5 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D4 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D3 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D2 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D1 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D0 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D9 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D8 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D7 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D6 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D5 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D4 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D3 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D2 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D1 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D0 GT Source 
(Pos ((:*) xi xl), Pos ((:*) yi yl), Trich xl yl rl, Trich xi yi ri, CS ri rl r) => Trich ((:*) xi xl) ((:*) yi yl) r Source 

trich :: Trich x y r => z -> x -> r Source

value-level reflection function for the comparison type-level assertion

Type-level values denoting comparison results

data LT Source

Lower than

Instances

Trich D8 D9 LT Source 
Trich D7 D9 LT Source 
Trich D7 D8 LT Source 
Trich D6 D9 LT Source 
Trich D6 D8 LT Source 
Trich D6 D7 LT Source 
Trich D5 D9 LT Source 
Trich D5 D8 LT Source 
Trich D5 D7 LT Source 
Trich D5 D6 LT Source 
Trich D4 D9 LT Source 
Trich D4 D8 LT Source 
Trich D4 D7 LT Source 
Trich D4 D6 LT Source 
Trich D4 D5 LT Source 
Trich D3 D9 LT Source 
Trich D3 D8 LT Source 
Trich D3 D7 LT Source 
Trich D3 D6 LT Source 
Trich D3 D5 LT Source 
Trich D3 D4 LT Source 
Trich D2 D9 LT Source 
Trich D2 D8 LT Source 
Trich D2 D7 LT Source 
Trich D2 D6 LT Source 
Trich D2 D5 LT Source 
Trich D2 D4 LT Source 
Trich D2 D3 LT Source 
Trich D1 D9 LT Source 
Trich D1 D8 LT Source 
Trich D1 D7 LT Source 
Trich D1 D6 LT Source 
Trich D1 D5 LT Source 
Trich D1 D4 LT Source 
Trich D1 D3 LT Source 
Trich D1 D2 LT Source 
Trich D0 D9 LT Source 
Trich D0 D8 LT Source 
Trich D0 D7 LT Source 
Trich D0 D6 LT Source 
Trich D0 D5 LT Source 
Trich D0 D4 LT Source 
Trich D0 D3 LT Source 
Trich D0 D2 LT Source 
Trich D0 D1 LT Source 
Pos ((:*) yi yl) => Trich D9 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D8 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D7 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D6 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D5 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D4 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D3 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D2 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D1 ((:*) yi yl) LT Source 
Pos ((:*) yi yl) => Trich D0 ((:*) yi yl) LT Source 

data GT Source

Greater than

Instances

Trich D9 D8 GT Source 
Trich D9 D7 GT Source 
Trich D9 D6 GT Source 
Trich D9 D5 GT Source 
Trich D9 D4 GT Source 
Trich D9 D3 GT Source 
Trich D9 D2 GT Source 
Trich D9 D1 GT Source 
Trich D9 D0 GT Source 
Trich D8 D7 GT Source 
Trich D8 D6 GT Source 
Trich D8 D5 GT Source 
Trich D8 D4 GT Source 
Trich D8 D3 GT Source 
Trich D8 D2 GT Source 
Trich D8 D1 GT Source 
Trich D8 D0 GT Source 
Trich D7 D6 GT Source 
Trich D7 D5 GT Source 
Trich D7 D4 GT Source 
Trich D7 D3 GT Source 
Trich D7 D2 GT Source 
Trich D7 D1 GT Source 
Trich D7 D0 GT Source 
Trich D6 D5 GT Source 
Trich D6 D4 GT Source 
Trich D6 D3 GT Source 
Trich D6 D2 GT Source 
Trich D6 D1 GT Source 
Trich D6 D0 GT Source 
Trich D5 D4 GT Source 
Trich D5 D3 GT Source 
Trich D5 D2 GT Source 
Trich D5 D1 GT Source 
Trich D5 D0 GT Source 
Trich D4 D3 GT Source 
Trich D4 D2 GT Source 
Trich D4 D1 GT Source 
Trich D4 D0 GT Source 
Trich D3 D2 GT Source 
Trich D3 D1 GT Source 
Trich D3 D0 GT Source 
Trich D2 D1 GT Source 
Trich D2 D0 GT Source 
Trich D1 D0 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D9 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D8 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D7 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D6 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D5 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D4 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D3 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D2 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D1 GT Source 
Pos ((:*) yi yl) => Trich ((:*) yi yl) D0 GT Source 

Abbreviated comparison assertions

class x :==: y Source

Equality abbreviated type-level assertion

Instances

Trich x y EQ => x :==: y Source 

class x :>: y Source

Greater-than abbreviated type-level assertion

Instances

Trich x y GT => x :>: y Source 

class x :<: y Source

Lower-than abbreviated type-level assertion

Instances

Trich x y LT => x :<: y Source 

class x :>=: y Source

Greater-than or equal abbreviated type-level assertion

Instances

(Succ x x', Trich x' y GT) => x :>=: y Source 

class x :<=: y Source

Lower-than or equal abbreviated type-level assertion

Instances

(Succ x' x, Trich x' y LT) => x :<=: y Source 

(==) :: x :==: y => x -> y -> () infix 4 Source

value-level reflection function for the equality abbreviated type-level assertion

(>) :: x :>: y => x -> y -> () infix 4 Source

value-level reflection function for the equality abbreviated type-level assertion

(<) :: x :<: y => x -> y -> () infix 4 Source

value-level reflection function for the lower-than abbreviated type-level assertion

(>=) :: x :>=: y => x -> y -> () infix 4 Source

value-level reflection function for the greater-than or equal abbreviated type-level assertion

(<=) :: x :<=: y => x -> y -> () infix 4 Source

value-level reflection function for the lower-than or equal abbreviated type-level assertion

Maximum/Minimum

class Max x y z | x y -> z Source

Maximum type-level relation

Instances

(Max' x y b z, Trich x y b) => Max x y z Source 

max :: Max x y z => x -> y -> z Source

value-level reflection function for the maximum type-level relation

class Min x y z | x y -> z Source

Minimum type-level relation

Instances

(Max' y x b z, Trich x y b) => Min x y z Source 

min :: Min x y z => x -> y -> z Source

value-level reflection function for the minimum type-level relation

Greatest Common Divisor

class (Nat x, Nat y, Nat gcd) => GCD x y gcd | x y -> gcd Source

Greatest Common Divisor type-level relation

Instances

(Nat x, Nat y, Trich x y cmp, IsZero y yz, GCD' x y yz cmp gcd) => GCD x y gcd Source 

gcd :: GCD x y z => x -> y -> z Source

value-level reflection function for the GCD type-level relation