[Haskell-beginners] An unsigned int class.

David Obwaller david.obwaller at gmx.at
Fri Jul 31 19:08:38 UTC 2015


Hi,

On Fri, Jul 31, 2015 at 09:30:35AM -0600, derek riemer wrote:
> Is there anything in haskell that represents an unsigned Int class?
> namely, something bounded below at 0?

The module Data.Word provides unsigned integral types with
modular arithmetic: Word (same size as Int), Word8, Word16,
etc.

    $ ghci
    > import Data.Word
    ...
    > maxBound :: Word
    18446744073709551615
    > maxBound :: Word8
    255
    > maxBound :: Word32
    4294967295
    > 0 - 1 :: Word8
    255
    > maxBound + 1 :: Word8
    0

Is that what you are looking for?

http://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Word.html

David


More information about the Beginners mailing list