f47aa8fe0c30647817a4f2996b14c93652f4d97e
[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 import PrelBase
16
17 infixl 8 `shift`, `rotate`
18 infixl 7 .&.
19 infixl 6 `xor`
20 infixl 5 .|.
21
22 class Bits a where
23   (.&.), (.|.), xor :: a -> a -> a
24   complement        :: a -> a
25   shift             :: a -> Int -> a
26   rotate            :: a -> Int -> a
27   bit               :: Int -> a
28   setBit            :: a -> Int -> a
29   clearBit          :: a -> Int -> a
30   complementBit     :: a -> Int -> a
31   testBit           :: a -> Int -> Bool
32   bitSize           :: a -> Int
33   isSigned          :: a -> Bool
34
35 shiftL, shiftR   :: Bits a => a -> Int -> a
36 rotateL, rotateR :: Bits a => a -> Int -> a
37 shiftL  a i = shift  a i
38 shiftR  a i = shift  a (-i)
39 rotateL a i = rotate a i
40 rotateR a i = rotate a (-i)
41 \end{code}