Copyright | Alexey Khudyakov |
---|---|
License | BSD3-style (see LICENSE) |
Maintainer | Alexey Khudyakov <alexey.skladnoy@gmail.com> |
Stability | unstable |
Portability | unportable (GHC only) |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module contain interface type classes for operations with type level numbers.
Synopsis
- type family Compare n m :: *
- compareN :: n -> m -> Compare n m
- data IsLesser
- data IsEqual
- data IsGreater
- class Lesser n m
- class LesserEq n m
- class Greater n m
- class GreaterEq n m
- class Positive n
- class NonZero n
- type family Next n :: *
- nextN :: n -> Next n
- type family Prev n :: *
- prevN :: n -> Prev n
- type family Negate n :: *
- negateN :: n -> Negate n
- type family Add n m :: *
- addN :: n -> m -> Add n m
- type family Sub n m :: *
- subN :: n -> m -> Sub n m
- type family Mul n m :: *
- mulN :: n -> m -> Mul n m
- type family Div n m :: *
- divN :: n -> m -> Div n m
- type family Normalized n :: *
Comparison of numbers
type family Compare n m :: * Source #
Type family for comparing two numbers. It's expected that for any
two valid n
and m
'Compare n m' is equal to IsLess when 'n<m', IsEqual
when 'n=m' and IsGreater when 'n>m'.
Instances
type Compare Z Z Source # | |
Defined in TypeLevel.Number.Nat | |
type Compare Z (O n) Source # | |
Defined in TypeLevel.Number.Nat | |
type Compare Z (I n) Source # | |
Defined in TypeLevel.Number.Nat | |
type Compare (O n) Z Source # | |
Defined in TypeLevel.Number.Nat | |
type Compare (I n) Z Source # | |
Defined in TypeLevel.Number.Nat | |
type Compare (O n) (O m) Source # | |
Defined in TypeLevel.Number.Nat | |
type Compare (O n) (I m) Source # | |
Defined in TypeLevel.Number.Nat | |
type Compare (I n) (I m) Source # | |
Defined in TypeLevel.Number.Nat | |
type Compare (I n) (O m) Source # | |
Defined in TypeLevel.Number.Nat |
Data labels for types comparison
Specialized type classes
These type classes are meant to be used in contexts to ensure relations between numbers. For example:
someFunction :: Lesser n m => Data n -> Data m -> Data n someFunction = ...
They have generic instances and every number which is instance of Compare type family is instance of these type classes.
These instance could have problems. They weren't exensively tested. Also error messages are really unhelpful.
Numbers n and m are instances of this class if and only is n < m.
Numbers n and m are instances of this class if and only is n <= m.
Numbers n and m are instances of this class if and only is n > m.
Numbers n and m are instances of this class if and only is n >= m.
Special traits
Positive number.
Non-zero number. For naturals it's same as positive
Arithmetic operations on numbers
type family Next n :: * Source #
Next number.
Instances
type Next ZZ Source # | |
Defined in TypeLevel.Number.Int | |
type Next Z Source # | |
Defined in TypeLevel.Number.Nat | |
type Next (D1 n) Source # | |
Defined in TypeLevel.Number.Int | |
type Next (D0 n) Source # | |
Defined in TypeLevel.Number.Int | |
type Next (Dn n) Source # | |
Defined in TypeLevel.Number.Int | |
type Next (O n) Source # | |
Defined in TypeLevel.Number.Nat | |
type Next (I n) Source # | |
Defined in TypeLevel.Number.Nat |
type family Prev n :: * Source #
Previous number
Instances
type Prev ZZ Source # | |
Defined in TypeLevel.Number.Int | |
type Prev (D1 n) Source # | |
Defined in TypeLevel.Number.Int | |
type Prev (D0 n) Source # | |
Defined in TypeLevel.Number.Int | |
type Prev (Dn n) Source # | |
Defined in TypeLevel.Number.Int | |
type Prev (O (O n)) Source # | |
type Prev (O (I n)) Source # | |
type Prev (I Z) Source # | |
Defined in TypeLevel.Number.Nat | |
type Prev (I (O n)) Source # | |
type Prev (I (I n)) Source # | |
type family Negate n :: * Source #
Negate number.
Instances
type Negate ZZ Source # | |
Defined in TypeLevel.Number.Int | |
type Negate (D1 n) Source # | |
Defined in TypeLevel.Number.Int | |
type Negate (D0 n) Source # | |
Defined in TypeLevel.Number.Int | |
type Negate (Dn n) Source # | |
Defined in TypeLevel.Number.Int |
type family Add n m :: * Source #
Sum of two numbers.
Instances
type family Sub n m :: * Source #
Difference of two numbers.
Instances
type family Mul n m :: * Source #
Product of two numbers.
Instances
type Mul n Z Source # | |
Defined in TypeLevel.Number.Nat | |
type Mul n ZZ Source # | |
Defined in TypeLevel.Number.Int | |
type Mul n (O m) Source # | |
Defined in TypeLevel.Number.Nat | |
type Mul n (I m) Source # | |
Defined in TypeLevel.Number.Nat | |
type Mul n (D0 m) Source # | |
Defined in TypeLevel.Number.Int | |
type Mul n (D1 m) Source # | |
Defined in TypeLevel.Number.Int | |
type Mul n (Dn m) Source # | |
Defined in TypeLevel.Number.Int |
type family Div n m :: * Source #
Division of two numbers. n
and m
should be instances of this
class only if remainder of 'n/m' is zero.
Special classes
type family Normalized n :: * Source #
Usually numbers have non-unique representation. This type family is canonical representation of number.
Instances
type Normalized ZZ Source # | |
Defined in TypeLevel.Number.Int | |
type Normalized Z Source # | |
Defined in TypeLevel.Number.Nat | |
type Normalized (D1 n) Source # | |
Defined in TypeLevel.Number.Int | |
type Normalized (D0 n) Source # | |
Defined in TypeLevel.Number.Int | |
type Normalized (Dn n) Source # | |
Defined in TypeLevel.Number.Int | |
type Normalized (O n) Source # | |
Defined in TypeLevel.Number.Nat | |
type Normalized (I n) Source # | |
Defined in TypeLevel.Number.Nat |