60c9fedd1fc9a9da6c294f9d66c80d382b6dcc48
[ghc-hetmet.git] / ghc / lib / exts / ByteArray.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1994-1997
3 %
4 \section[ByteArray]{The @ByteArray@ interface}
5
6 Immutable, read-only chunks of bytes, the @ByteArray@ collects
7 together the definitions in @ArrBase@ and exports them as one.
8
9 \begin{code}
10 module ByteArray
11        (
12         ByteArray(..),  -- not abstract, for now.
13         Ix,
14
15         --Indexing of ordinary @Arrays@ is standard Haskell and isn't defined here.
16         indexCharArray,       -- :: Ix ix => ByteArray ix -> ix -> Char 
17         indexIntArray,        -- :: Ix ix => ByteArray ix -> ix -> Int
18         indexWordArray,       -- :: Ix ix => ByteArray ix -> ix -> Word
19         indexAddrArray,       -- :: Ix ix => ByteArray ix -> ix -> Addr
20         indexFloatArray,      -- :: Ix ix => ByteArray ix -> ix -> Float
21         indexDoubleArray,     -- :: Ix ix => ByteArray ix -> ix -> Double
22         indexStablePtrArray   -- :: Ix ix => ByteArray ix -> ix -> (StablePtr a)
23  
24        ) where
25
26 import PrelArr
27 import PrelBase
28 import PrelForeign
29 import PrelStable
30 import Ix
31 \end{code}
32
33 \begin{code}
34 indexStablePtrArray    :: Ix ix => ByteArray ix -> ix -> (StablePtr a)
35 indexStablePtrArray (ByteArray ixs barr#) n
36   = case (index ixs n)                  of { I# n# ->
37     case indexStablePtrArray# barr# n#  of { r# ->
38     (StablePtr r#)}}
39 \end{code}