[Haskell-cafe] Positive integers
lemming at henning-thielemann.de
Fri Mar 24 07:23:00 EST 2006
On Fri, 24 Mar 2006, Malcolm Wallace wrote:
> Daniel McAllansmith <dagda at xtra.co.nz> wrote:
>> Unless I've missed it, there is no typeclass for positive integers in
>> GHC. Is there any particular reason it doesn't exist?
>> Also, it seems Word would be a far better type in the likes of (!!),
>> length, etc. Is it just tradition that resulted in the use of Int?
> There is a good argument that what you really want here is the lazy
> infinite natural numbers. Think Peano:
> data Natural = Zero | Succ Natural
> The clear correspondance between lazy lists and the size/index of a lazy
> list makes this type fairly compelling. It can be jolly useful,
> particularly with infinite streams, to be able to compute
> (length xs > n)
> without forcing the evaluation of the list to more than n places.
Fortunately there are already List functions like genericLength and
genericTake, which can handle such a number type. Shouldn't be Peano
numbers part of the standard libraries?
More information about the Haskell-Cafe