Copyright | Alexey Khudyakov |
---|---|
License | BSD3-style (see LICENSE) |
Maintainer | Alexey Khudyakov <alexey.skladnoy@gmail.com> |
Stability | unstable |
Portability | unportable (GHC only) |
Safe Haskell | None |
Language | Haskell2010 |
This is type level natural numbers. They are represented using binary encoding which means that reasonable large numbers could be represented. With default context stack depth (20) maximal number is 2^18-1 (262143).
Z = 0 I Z = 1 O (I Z) = 2 I (I Z) = 3 O (O (I Z)) = 4 ...
It's easy to see that representation for each number is not unique. One could add any numbers of leading zeroes:
I Z = I (O Z) = I (O (O Z)) = 1
In order to enforce uniqueness of representation only numbers without leading zeroes are members of Nat type class. This means than types are equal if and only if numbers are equal.
Natural numbers support comparison and following operations: Next, Prev, Add, Sub, Mul. All operations on numbers return normalized numbers.
Interface type classes are reexported from TypeLevel.Number.Classes
Natural numbers
One bit.
Instances
Zero bit.
Instances
Bit stream terminator.
Instances
Type class for natural numbers. Only numbers without leading zeroes are members of this type class.
toInt :: Integral i => n -> i Source #
Convert natural number to integral value. It's not checked whether value could be represented.
Lifting
Some natural number
withNat :: forall i a. Integral i => (forall n. Nat n => n -> a) -> i -> a Source #
Apply function which could work with any Nat
value only know at runtime.
Template haskell utilities
Here is usage example for natT:
n123 :: $(natT 123) n123 = undefined
module TypeLevel.Number.Classes