HORIZON HASKELLDocslts/ghc-9.14.x7a6c33e2026-10-12Search packagesCtrl K
Theme: |

GHC 9.14.1 · lts/ghc-9.14.x · 7a6c33e · 2026-10-12

Modulenatural-arithmetic-0.2.4.0Haskell2010

Arithmetic.Nat

Contents
  1. Addition
  2. Subtraction
  3. Division
  4. Multiplication
  5. Successor
  6. Predecessor
  7. Compare
  8. Constants
  9. Unboxed Constants
  10. Unboxed Pattern Synonyms
  11. Convert
  12. Substitute
Synopsis

Addition

Subtraction

Division

Multiplication

Successor

Predecessor

valuewithPred#
  1. :: Nat# a
  2. -> 0 <# a
  3. -> forall (b :: Nat). Nat# b -> a :=:# (b + 1) -> t
  4. -> t

If a natural number is greater than zero, we can operate on its predecessor.

Compare

Constants

valueconstant :: KnownNat n => Nat n

Use GHC's built-in type-level arithmetic to create a witness of a type-level number. This only reduces if the number is a constant.

Unboxed Constants

Unboxed Pattern Synonyms

Convert

valuedemote :: Nat n -> Int

Extract the Int from a Nat. This is intended to be used at a boundary where a safe interface meets the unsafe primitives on top of which it is built.

valuewith :: Int -> (forall (n :: Nat). Nat n -> a) -> a

Run a computation on a witness of a type-level number. The argument Int must be greater than or equal to zero. This is not checked. Failure to upload this invariant will lead to a segfault.

Substitute