Daniel McAllansmith <[EMAIL PROTECTED]> 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.
Of course, if the naturals were actually represented in Peano (unary)
form, that would be somewhat inefficient, but there are various
strategies that can be used to make the representation smaller whilst
retaining their nice properties.
Regards,
Malcolm
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe