Data.Nat
v11.3.15 • Natural Numbers
Natural numbers implemented in Church fold style.
Types
Nat :: *
Inductive natural numbers in Church-encoded style (Zero and Successor).
Implementationdata Nat = Zero | Succ Nat
Foreigns
No foreign functions defined in this module.
Functions
plus :: Nat -> Nat -> Nat
Addition of two natural numbers via Church induction.
Implementationplus m n = case m of
Zero -> n
Succ p -> Succ p
mult :: Nat -> Nat -> Nat
Multiplication of two natural numbers via repeated addition.
Implementationmult m n = case m of
Zero -> Zero
Succ p -> plus n p
fold :: Nat -> (Nat -> B -> B) -> B -> B
The Church eliminator for natural numbers.
Implementationfold n f z = case n of
Zero -> z
Succ p -> f p
is_zero :: Nat -> Bool
Returns True if the number is Zero.
Implementationis_zero n = case n of
Zero -> True
Succ p -> False