1 {-# OPTIONS_GHC -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 -----------------------------------------------------------------------------

17 (

18 -- * Unsigned integral types

20 Word,

23 -- * Notes

25 -- $notes

28 #ifdef __GLASGOW_HASKELL__

30 #endif

32 #ifdef __HUGS__

34 #endif

36 #ifdef __NHC__

40 #endif

42 {- $notes

44 * All arithmetic is performed modulo 2^n, where n is the number of

45 bits in the type. One non-obvious consequence of this is that 'Prelude.negate'

46 should /not/ raise an error on negative arguments.

48 * For coercing between any two integer types, use

49 'Prelude.fromIntegral', which is specialized for all the

50 common cases so should be fast enough. Coercing word types to and

51 from integer types preserves representation, not sign.

53 * It would be very natural to add a type @Natural@ providing an unbounded

54 size unsigned integer, just as 'Prelude.Integer' provides unbounded

55 size signed integers. We do not do that yet since there is no demand

56 for it.

58 * The rules that hold for 'Prelude.Enum' instances over a bounded type

59 such as 'Prelude.Int' (see the section of the Haskell report dealing

60 with arithmetic sequences) also hold for the 'Prelude.Enum' instances

61 over the various 'Word' types defined here.

63 * Right and left shifts by amounts greater than or equal to the width

64 of the type result in a zero result. This is contrary to the

65 behaviour in C, which is undefined; a common interpretation is to

66 truncate the shift count to the width of the type, for example @1 \<\<

67 32 == 1@ in some C implementations.

68 -}