natural-numbers- Natural numbers

Safe HaskellSafe-Infered



Support for natural numbers.



data Natural Source

The type of natural numbers.

Note that matching a natural number against a negative pattern might not work as you expect. For example, evaluating the following expression results in a run-time error, instead of the result "plus five":

case 5 :: Natural of
    -5 -> "minus five"
     5 -> "plus five"

The reason is that the == operator of Natural is used for checking if the patterns match, making it necessary to convert -5 to Natural.

monus :: Natural -> Natural -> NaturalSource

Yields the monus of two natural numbers, which is their difference if the first number is greater than the second, and zero otherwise.

data View Source

A data type for views of natural numbers.

view :: Natural -> ViewSource

Yields the view of a natural number.

fold :: accu -> (accu -> accu) -> Natural -> accuSource

Folding of natural numbers.