[Haskell-cafe] positive Int

Ian Lynagh igloo at earth.li
Thu Aug 2 18:07:29 EDT 2007

On Thu, Aug 02, 2007 at 12:17:06PM -0700, brad clawsie wrote:
> as far as i know, the haskell standard does not define a basic Int
> type that is limited to positive numbers.

Haskell 98 doesn't have such a type, no, but in today's libraries there
is Data.Word.Word. Operations like subtraction will just wrap around
when they would otherwise go negative, though ("All arithmetic is
performed modulo 2^n").

> for example, 'length' returns an Int, but in reality it must always
> return a value 0 or greater. a potential counter-argument would be the
> need to possibly redefine Ord etc for this more narrow type...

The main worry I can see with doing that is, would you need to keep
explicitly converting between Int and Word? It might be possible to
convert enough things to Word that it doesn't matter.

You'd also break lots of programs, of course.


More information about the Haskell-Cafe mailing list