natural-arithmetic-0.1.0.0: Arithmetic of natural numbers

Safe HaskellNone
LanguageHaskell2010

Arithmetic.Nat

Contents

Synopsis

Addition

plus :: Nat a -> Nat b -> Nat (a + b) Source #

Add two numbers.

Subtraction

monus :: Nat a -> Nat b -> Maybe (Difference a b) Source #

Subtract the second argument from the first argument.

Successor

succ :: Nat a -> Nat (a + 1) Source #

The successor of a number.

Compare

testEqual :: Nat a -> Nat b -> Maybe (a :=: b) Source #

Are the two arguments equal to one another?

testLessThan :: Nat a -> Nat b -> Maybe (a < b) Source #

Is the first argument strictly less than the second argument?

testLessThanEqual :: Nat a -> Nat b -> Maybe (a <= b) Source #

Is the first argument less-than-or-equal-to the second argument?

(=?) :: Nat a -> Nat b -> Maybe (a :=: b) Source #

Infix synonym of testEqual.

(<?) :: Nat a -> Nat b -> Maybe (a < b) Source #

Infix synonym of testLessThan.

(<=?) :: Nat a -> Nat b -> Maybe (a <= b) Source #

Infix synonym of testLessThanEqual.

Constants

zero :: Nat 0 Source #

The number zero.

one :: Nat 1 Source #

The number one.

constant :: forall n. KnownNat n => Nat n Source #

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.

Demote

demote :: Nat n -> Int Source #

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.