MyNixOS website logo
Description

Type level numbers using existing Nat functionality.

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.

typenums

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.

Usage

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 = -- ...

Syntax

  • 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.

Metadata

Version

0.1.4

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows