type-level-numbers-0.1.1.1: Type level numbers implemented using type families.

Portabilityunportable (GHC only)
Stabilityunstable
MaintainerAlexey Khudyakov <alexey.skladnoy@gmail.com>
Safe HaskellNone

TypeLevel.Number.Int

Contents

Description

Type level signed integer numbers are implemented using balanced ternary encoding much in the same way as natural numbers.

Currently following operations are supported: Next, Prev, Add, Sub, Mul.

Synopsis

Integer numbers

data ZZ Source

Digit stream terminator

Instances

data Dn n Source

Digit -1

Instances

IntT (Dn n) => Show (Dn n) 
IntT (Dn n) => IntT (D1 (Dn n)) 
IntT (Dn n) => IntT (D0 (Dn n)) 
IntT (Dn ZZ) 
IntT (D1 n) => IntT (Dn (D1 n)) 
IntT (D0 n) => IntT (Dn (D0 n)) 
IntT (Dn n) => IntT (Dn (Dn n)) 

data D0 n Source

Digit 0

Instances

IntT (D0 n) => Show (D0 n) 
IntT (D0 n) => IntT (D1 (D0 n)) 
IntT (D1 n) => IntT (D0 (D1 n)) 
IntT (D0 n) => IntT (D0 (D0 n)) 
IntT (Dn n) => IntT (D0 (Dn n)) 
IntT (D0 n) => IntT (Dn (D0 n)) 

data D1 n Source

Digit 1

Instances

IntT (D1 n) => Show (D1 n) 
IntT (D1 ZZ) 
IntT (D1 n) => IntT (D1 (D1 n)) 
IntT (D0 n) => IntT (D1 (D0 n)) 
IntT (Dn n) => IntT (D1 (Dn n)) 
IntT (D1 n) => IntT (D0 (D1 n)) 
IntT (D1 n) => IntT (Dn (D1 n)) 

class IntT n whereSource

Type class for type level integers. Only numbers without leading zeroes are members of the class.

Methods

toInt :: Integral i => n -> iSource

Convert natural number to integral value. It's not checked whether value could be represented.

Instances

IntT ZZ 
IntT (D1 ZZ) 
IntT (D1 n) => IntT (D1 (D1 n)) 
IntT (D0 n) => IntT (D1 (D0 n)) 
IntT (Dn n) => IntT (D1 (Dn n)) 
IntT (D1 n) => IntT (D0 (D1 n)) 
IntT (D0 n) => IntT (D0 (D0 n)) 
IntT (Dn n) => IntT (D0 (Dn n)) 
IntT (Dn ZZ) 
IntT (D1 n) => IntT (Dn (D1 n)) 
IntT (D0 n) => IntT (Dn (D0 n)) 
IntT (Dn n) => IntT (Dn (Dn n)) 

Lifting

data SomeInt Source

Some natural number

withInt :: forall i a. Integral i => (forall n. IntT n => n -> a) -> i -> aSource

Apply function which could work with any Nat value only know at runtime.

Template haskell utilities

intT :: Integer -> TypeQSource

Generate type for integer number.