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