![]() | ![]() | ![]() | Natural numbers | Documentation and user's manual | Table of contents | OCaml programs |
nat_1
is provided by the Nat_1
module.
Specification of the type nat_1 |
This type gives each natural number a unique representation.
It is equipped with these five functions:
Nat_1.mli file) shows the types of these five functions:
nat_1 is an abstract type.
|
Use nat_1 . For each of the following specifications of functional values first write a mathematical formula then write a recursive definition based on the formula and meeting the specification: |
Name: add .
Type: nat_1 * nat_1 -> nat_1 .
Adds two natural numbers.
|
A mathematical formula:
This recursive definition of
|
Name: mult .
Type: nat_1 * nat_1 -> nat_1 .
Multiply two natural numbers.
|
A mathematical formula:
This recursive definition of
|
Name: greater_than .
Type: nat_1 * nat_1 -> bool .
Tests whether m > n given a pair (m, n) of natural numbers.
|
A mathematical formula:
This recursive definition of
|
Name: subtract .
Type: nat_1 * nat_1 -> nat_1 .
Returns the natural number m - n given a pair (m, n) of natural numbers where m is greater than of equal to n.
|
A mathematical formula:
This recursive definition of
|
The function failwith has type string -> 'a .
Its application stops the computation and prints its argument.
|
|
Name: nat_of_int .
Type: int -> nat_1 .
Converts a non-negative int value to the corresponding nat_1 value.
|
A mathematical formula:
This recursive definition of
|
Name: int_of_nat .
Type: nat_1 -> int .
Converts a nat_1 value to the corresponding int value.
|
A mathematical formula:
This recursive definition of
|
![]() | ![]() | ![]() | Natural numbers | Documentation and user's manual | Table of contents | OCaml programs |