    {-# LANGUAGE Unsafe #-}
    {-# LANGUAGE NoImplicitPrelude, RoleAnnotations #-}
    {-# OPTIONS_GHC -funbox-strict-fields #-}
    {-# OPTIONS_HADDOCK not-home #-}

    -----------------------------------------------------------------------------
    -- |
    -- Module      :  GHC.IOArray
    -- Copyright   :  (c) The University of Glasgow 2008
    -- License     :  see libraries/base/LICENSE
    --
    -- Maintainer  :  cvs-ghc@haskell.org
    -- Stability   :  internal
    -- Portability :  non-portable (GHC Extensions)
    --
    -- The IOArray type
    --
    -----------------------------------------------------------------------------

    module GHC.IOArray (
            IOArray(..),
            newIOArray, unsafeReadIOArray, unsafeWriteIOArray,
            readIOArray, writeIOArray,
            boundsIOArray
        ) where

    import GHC.Base
    import GHC.IO
    import GHC.Arr

    -- ---------------------------------------------------------------------------
    -- | An 'IOArray' is a mutable, boxed, non-strict array in the 'IO' monad.
    -- The type arguments are as follows:
    --
    --  * @i@: the index type of the array (should be an instance of 'Ix')
    --
    --  * @e@: the element type of the array.
    --
    --

    newtype IOArray i e = IOArray (STArray RealWorld i e)

    -- index type should have a nominal role due to Ix class. See also #9220.
    type role IOArray nominal representational

    -- explicit instance because Haddock can't figure out a derived one
    -- | @since 4.1.0.0
    instance Eq (IOArray i e) where
      IOArray STArray RealWorld i e
    x == :: IOArray i e -> IOArray i e -> Bool
    == IOArray STArray RealWorld i e
    y = STArray RealWorld i e
    x forall a. Eq a => a -> a -> Bool
    == STArray RealWorld i e
    y

    -- |Build a new 'IOArray'
    newIOArray :: Ix i => (i,i) -> e -> IO (IOArray i e)
    {-# INLINE newIOArray #-}
    newIOArray :: forall i e. Ix i => (i, i) -> e -> IO (IOArray i e)
    newIOArray (i, i)
    lu e
    initial  = forall a. ST RealWorld a -> IO a
    stToIO forall a b. (a -> b) -> a -> b
    $ do {STArray RealWorld i e
    marr <- forall i e s. Ix i => (i, i) -> e -> ST s (STArray s i e)
    newSTArray (i, i)
    lu e
    initial; forall (m :: * -> *) a. Monad m => a -> m a
    return (forall i e. STArray RealWorld i e -> IOArray i e
    IOArray STArray RealWorld i e
    marr)}

    -- | Read a value from an 'IOArray'
    unsafeReadIOArray  :: IOArray i e -> Int -> IO e
    {-# INLINE unsafeReadIOArray #-}
    unsafeReadIOArray :: forall i e. IOArray i e -> Int -> IO e
    unsafeReadIOArray (IOArray STArray RealWorld i e
    marr) Int
    i = forall a. ST RealWorld a -> IO a
    stToIO (forall s i e. STArray s i e -> Int -> ST s e
    unsafeReadSTArray STArray RealWorld i e
    marr Int
    i)

    -- | Write a new value into an 'IOArray'
    unsafeWriteIOArray :: IOArray i e -> Int -> e -> IO ()
    {-# INLINE unsafeWriteIOArray #-}
    unsafeWriteIOArray :: forall i e. IOArray i e -> Int -> e -> IO ()
    unsafeWriteIOArray (IOArray STArray RealWorld i e
    marr) Int
    i e
    e = forall a. ST RealWorld a -> IO a
    stToIO (forall s i e. STArray s i e -> Int -> e -> ST s ()
    unsafeWriteSTArray STArray RealWorld i e
    marr Int
    i e
    e)

    -- | Read a value from an 'IOArray'
    readIOArray  :: Ix i => IOArray i e -> i -> IO e
    readIOArray :: forall i e. Ix i => IOArray i e -> i -> IO e
    readIOArray (IOArray STArray RealWorld i e
    marr) i
    i = forall a. ST RealWorld a -> IO a
    stToIO (forall i s e. Ix i => STArray s i e -> i -> ST s e
    readSTArray STArray RealWorld i e
    marr i
    i)

    -- | Write a new value into an 'IOArray'
    writeIOArray :: Ix i => IOArray i e -> i -> e -> IO ()
    writeIOArray :: forall i e. Ix i => IOArray i e -> i -> e -> IO ()
    writeIOArray (IOArray STArray RealWorld i e
    marr) i
    i e
    e = forall a. ST RealWorld a -> IO a
    stToIO (forall i s e. Ix i => STArray s i e -> i -> e -> ST s ()
    writeSTArray STArray RealWorld i e
    marr i
    i e
    e)

    {-# INLINE boundsIOArray #-}
    boundsIOArray :: IOArray i e -> (i,i)
    boundsIOArray :: forall i e. IOArray i e -> (i, i)
    boundsIOArray (IOArray STArray RealWorld i e
    marr) = forall s i e. STArray s i e -> (i, i)
    boundsSTArray STArray RealWorld i e
    marr