Version 1 (modified by 12 years ago) (diff) | ,
---|

# Natural numbers

A lot of common functions do recursion over the natural numbers. But Haskell does not have a Natural number type! Everyone uses Integer instead. This can lead to subtle bugs, because no-one considers the negative number case in their definitions. There were even examples of such bugs in the Prelude (take, drop) for about ten years.

So, let's add a Natural number type. Ideally, we should also restrict the interpretation of literal numeric patterns to values of Natural, so that any unintentional use of features belonging to other numeric types can be flagged as a static error.

## Examples

fib 0 = 1 fib 1 = 1 fib n = fib (n-1) + fib (n-2)

But what is the value of **fib (-3)**? A runtime stack overflow! Much better to catch this error at compile time.