[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / lib / exts / Bits.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1998
3 %
4 \section[Bits]{The @Bits@ interface}
5
6 Defines the @Bits@ class containing bit-based operations.
7 See library document for details on the semantics of the
8 individual operations.
9
10 \begin{code}
11 {-# OPTIONS -fno-implicit-prelude #-}
12
13 module Bits where
14
15 #ifdef __HUGS__
16 import PreludeBuiltin
17 #else
18 import PrelBase
19 #endif
20
21 --ADR: The fixity for .|. conflicts with that for .|. in Fran.
22 --     Removing all fixities is a fairly safe fix; fixing the "one fixity
23 --     per symbol per program" limitation in Hugs would take a lot longer.
24 #ifndef __HUGS__
25 infixl 8 `shift`, `rotate`
26 infixl 7 .&.
27 infixl 6 `xor`
28 infixl 5 .|.
29 #endif
30
31 class Bits a where
32   (.&.), (.|.), xor :: a -> a -> a
33   complement        :: a -> a
34   shift             :: a -> Int -> a
35   rotate            :: a -> Int -> a
36   bit               :: Int -> a
37   setBit            :: a -> Int -> a
38   clearBit          :: a -> Int -> a
39   complementBit     :: a -> Int -> a
40   testBit           :: a -> Int -> Bool
41   bitSize           :: a -> Int
42   isSigned          :: a -> Bool
43
44 shiftL, shiftR   :: Bits a => a -> Int -> a
45 rotateL, rotateR :: Bits a => a -> Int -> a
46 shiftL  a i = shift  a i
47 shiftR  a i = shift  a (-i)
48 rotateL a i = rotate a i
49 rotateR a i = rotate a (-i)
50 \end{code}