[project @ 2002-10-09 17:08:18 by malcolm]
[packages/random.git] / Data / Word.hs
1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module : Data.Word
5 -- Copyright : (c) The University of Glasgow 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
7 --
8 -- Maintainer : libraries@haskell.org
9 -- Stability : experimental
10 -- Portability : portable
11 --
12 -- Unsigned integer types.
13 --
14 -----------------------------------------------------------------------------
15
16 module Data.Word
17 (
18 -- * Unsigned integral types
19
20 Word,
21 Word8, Word16, Word32, Word64,
22
23 -- * Notes
24
25 -- $notes
26 ) where
27
28 #ifdef __GLASGOW_HASKELL__
29 import GHC.Word
30 #endif
31
32 #ifdef __HUGS__
33 import Hugs.Word
34 #endif
35
36 #ifdef __NHC__
37 import NHC.FFI (Word8, Word16, Word32, Word64)
38 type Word = Word32
39 #endif
40
41 {- $notes
42
43 * All arithmetic is performed modulo 2^n, where n is the number of
44 bits in the type. One non-obvious consequence of this is that 'negate'
45 should /not/ raise an error on negative arguments.
46
47 * For coercing between any two integer types, use
48 'fromIntegral', which is specialized for all the
49 common cases so should be fast enough. Coercing word types to and
50 from integer types preserves representation, not sign.
51
52 * It would be very natural to add a type 'Natural' providing an unbounded
53 size unsigned integer, just as 'Integer' provides unbounded
54 size signed integers. We do not do that yet since there is no demand
55 for it.
56
57 * The rules that hold for 'Enum' instances over a bounded type
58 such as 'Int' (see the section of the Haskell report dealing
59 with arithmetic sequences) also hold for the 'Enum' instances
60 over the various 'Word' types defined here.
61
62 * Right and left shifts by amounts greater than or equal to the width
63 of the type result in a zero result. This is contrary to the
64 behaviour in C, which is undefined; a common interpretation is to
65 truncate the shift count to the width of the type, for example @1 \<\<
66 32 == 1@ in some C implementations.
67 -}