BSD-3-Clause licensed by AdituV
Maintained by [email protected]
This version can be pinned in stack with:typenums-0.1.4@sha256:1e7ed4d18db4a5d485716978bb588863fa1ff40afe7098e3b304f0f2b4b3687a,1933

Module documentation for 0.1.4

Depends on 1 package(full list with versions):


Hackage example workflow BSD3 license

Type level numbers using existing Nat functionality. Uses kind-polymorphic typeclasses and type families to facilitate more general code compatible with existing code using type-level Naturals.


Import either Data.TypeNums or Data.TypeLits instead of GHC.TypeLits. Some definitions conflict with GHC.TypeLits, so if you really must import it, use an explicit import list.

This library is intended to be used in a kind-polymorphic way, such that a type-level integer parameter can be written as a natural, and a rational can be written as either of the other two. As an example:

{-# LANGUAGE PolyKinds #-}

data SomeType (n :: k) = SomeType

useSomeType :: KnownInt n => SomeType n -> _
useSomeType = -- ...


  • Positive integers are written as natural numbers, as before. Optionally they can also be written as Pos n.
  • Negative integers are written as Neg n.
  • Ratios are written as n :% d, where n can be a natural number, Pos n, or Neg n, and d is a natural number.

Addition, subtraction and multiplication at type level are all given as infix operators with standard notation, and are compatible with any combination of the above types. Equality and comparison constraints are likewise available for any combination of the above types.

N.B. The equality constraint conflicts with that in Data.Type.Equality. The (==) operator from Data.Type.Equality is re-exported as (==?) from both Data.TypeNums and Data.TypeLits.


Change log

typenums uses PVP Versioning. The change log is available on GitHub.


  • Added rational simplification
  • Added more arithmetic functionality:
    • Reciprocals
    • Division
    • Integer division and remainder (DivMod, QuotRem…)
    • Absolute value
    • GCD, LCM
    • Exponentiation
    • Rounding (Floor, Ceiling, Truncate)
    • Integer logarithm
  • Rewrote arithmetic tests to compare types directly
  • Updated arithmetic operations to simplify rationals
  • (==?) now considers “logical equality” for numbers rather than exact type representational equality.


  • Dropped support for GHC 8.2
  • Added support for GHCs 8.8+
  • (#4) Added more cases for (<=?) type level comparison
  • Fixed incorrect behaviour with (<=?) type level comparison
    • Comparison of two rationals was previously incorrect
  • Added tests for comparison

  • Fix build failure on GHC 8.6 by adding conditional NoStarIsType langauge pragma


  • (#2) Refactored type-level arithmetic so that the type families are exposed from an Internal module.

  • Add UndecidableInstances language extension to Data.TypeNums.Rats. This fixes a compilation error with GHC HEAD.


  • (#1) Added existentially-quantified datatypes SomeInt and SomeRat to handle type-level Ints and Rats that are not statically known. Added functions someIntVal and someRatVal to construct these from an Integer/Rational value.

  • Initial Haddock release
  • Defined type-level integers and rationals
  • Defined polykinded arithmetic over nats, ints and rats
  • Defined polykinded comparison over nats, ints and rats
  • Added Data.TypeLits module