1 {-# LANGUAGE NoImplicitPrelude #-}
2 {-# OPTIONS_GHC -funbox-strict-fields #-}
3 {-# OPTIONS_HADDOCK hide #-}
4 -----------------------------------------------------------------------------
6 -- Module : GHC.IOArray
7 -- Copyright : (c) The University of Glasgow 2008
8 -- License : see libraries/base/LICENSE
10 -- Maintainer : cvs-ghc@haskell.org
11 -- Stability : internal
12 -- Portability : non-portable (GHC Extensions)
16 -----------------------------------------------------------------------------
20 newIOArray, unsafeReadIOArray, unsafeWriteIOArray,
21 readIOArray, writeIOArray,
29 -- ---------------------------------------------------------------------------
30 -- | An 'IOArray' is a mutable, boxed, non-strict array in the 'IO' monad.
31 -- The type arguments are as follows:
33 -- * @i@: the index type of the array (should be an instance of 'Ix')
35 -- * @e@: the element type of the array.
39 newtype IOArray i e = IOArray (STArray RealWorld i e)
41 -- explicit instance because Haddock can't figure out a derived one
42 instance Eq (IOArray i e) where
43 IOArray x == IOArray y = x == y
45 -- |Build a new 'IOArray'
46 newIOArray :: Ix i => (i,i) -> e -> IO (IOArray i e)
47 {-# INLINE newIOArray #-}
48 newIOArray lu initial = stToIO $ do {marr <- newSTArray lu initial; return (IOArray marr)}
50 -- | Read a value from an 'IOArray'
51 unsafeReadIOArray :: Ix i => IOArray i e -> Int -> IO e
52 {-# INLINE unsafeReadIOArray #-}
53 unsafeReadIOArray (IOArray marr) i = stToIO (unsafeReadSTArray marr i)
55 -- | Write a new value into an 'IOArray'
56 unsafeWriteIOArray :: Ix i => IOArray i e -> Int -> e -> IO ()
57 {-# INLINE unsafeWriteIOArray #-}
58 unsafeWriteIOArray (IOArray marr) i e = stToIO (unsafeWriteSTArray marr i e)
60 -- | Read a value from an 'IOArray'
61 readIOArray :: Ix i => IOArray i e -> i -> IO e
62 readIOArray (IOArray marr) i = stToIO (readSTArray marr i)
64 -- | Write a new value into an 'IOArray'
65 writeIOArray :: Ix i => IOArray i e -> i -> e -> IO ()
66 writeIOArray (IOArray marr) i e = stToIO (writeSTArray marr i e)
68 {-# INLINE boundsIOArray #-}
69 boundsIOArray :: IOArray i e -> (i,i)
70 boundsIOArray (IOArray marr) = boundsSTArray marr