{-# LANGUAGE MagicHash, NoImplicitPrelude, UnboxedTuples #-}

module GHC.Event.Arr
    (
      Arr(..)
    , new
    , size
    , read
    , write
    ) where

import GHC.Base (($))
import GHC.Prim (MutableArray#, RealWorld, newArray#, readArray#,
                 sizeofMutableArray#, writeArray#)
import GHC.Types (IO(..), Int(..))

data Arr a = Arr (MutableArray# RealWorld a)

new :: a -> Int -> IO (Arr a)
new :: forall a. a -> Int -> IO (Arr a)
new a
defval (I# Int#
n#) = forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s0# ->
  case forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# a
defval State# RealWorld
s0# of (# State# RealWorld
s1#, MutableArray# RealWorld a
marr# #) -> (# State# RealWorld
s1#, forall a. MutableArray# RealWorld a -> Arr a
Arr MutableArray# RealWorld a
marr# #)

size :: Arr a -> Int
size :: forall a. Arr a -> Int
size (Arr MutableArray# RealWorld a
a) = Int# -> Int
I# (forall d a. MutableArray# d a -> Int#
sizeofMutableArray# MutableArray# RealWorld a
a)

read :: Arr a -> Int -> IO a
read :: forall a. Arr a -> Int -> IO a
read (Arr MutableArray# RealWorld a
a) (I# Int#
n#) = forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s0# ->
  case forall d a.
MutableArray# d a -> Int# -> State# d -> (# State# d, a #)
readArray# MutableArray# RealWorld a
a Int#
n# State# RealWorld
s0# of (# State# RealWorld
s1#, a
val #) -> (# State# RealWorld
s1#, a
val #)

write :: Arr a -> Int -> a -> IO ()
write :: forall a. Arr a -> Int -> a -> IO ()
write (Arr MutableArray# RealWorld a
a) (I# Int#
n#) a
val = forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s0# ->
  case forall d a. MutableArray# d a -> Int# -> a -> State# d -> State# d
writeArray# MutableArray# RealWorld a
a Int#
n# a
val State# RealWorld
s0# of State# RealWorld
s1# -> (# State# RealWorld
s1#, () #)