8af39b6d4d196cfaaa30c08dfefe3fa5c2ef13e4

1 {-# LANGUAGE Safe #-}

2 {-# LANGUAGE NoImplicitPrelude #-}

4 -----------------------------------------------------------------------------

5 -- |

6 -- Module : Data.Word

7 -- Copyright : (c) The University of Glasgow 2001

8 -- License : BSD-style (see the file libraries/base/LICENSE)

9 --

10 -- Maintainer : libraries@haskell.org

11 -- Stability : experimental

12 -- Portability : portable

13 --

14 -- Unsigned integer types.

15 --

16 -----------------------------------------------------------------------------

19 (

20 -- * Unsigned integral types

22 Word,

25 -- * byte swapping

28 -- * Notes

30 -- $notes

35 {- $notes

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

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

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

41 * For coercing between any two integer types, use

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

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

44 from integer types preserves representation, not sign.

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

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

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

49 for it.

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

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

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

54 over the various 'Word' types defined here.

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

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

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

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

60 32 == 1@ in some C implementations.

61 -}