1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
5 -- Copyright : (c) The University of Glasgow 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
8 -- Maintainer : libraries@haskell.org
9 -- Stability : experimental
10 -- Portability : portable
12 -- Unsigned integer types.
14 -----------------------------------------------------------------------------
18 -- * Unsigned integral types
23 Word8, Word16, Word32, Word64,
30 #ifdef __GLASGOW_HASKELL__
40 * All arithmetic is performed modulo 2^n, where n is the number of
41 bits in the type. One non-obvious consequence of this is that 'negate'
42 should /not/ raise an error on negative arguments.
44 * For coercing between any two integer types, use
45 'fromIntegral', which is specialized for all the
46 common cases so should be fast enough. Coercing word types to and
47 from integer types preserves representation, not sign.
49 * It would be very natural to add a type 'Natural' providing an unbounded
50 size unsigned integer, just as 'Integer' provides unbounded
51 size signed integers. We do not do that yet since there is no demand
54 * The rules that hold for 'Enum' instances over a bounded type
55 such as 'Int' (see the section of the Haskell report dealing
56 with arithmetic sequences) also hold for the 'Enum' instances
57 over the various 'Word' types defined here.
59 * Right and left shifts by amounts greater than or equal to the width
60 of the type result in a zero result. This is contrary to the
61 behaviour in C, which is undefined; a common interpretation is to
62 truncate the shift count to the width of the type, for example @1 \<\<
63 32 == 1@ in some C implementations.