1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
{-# 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 defval (I# n#) = IO $ \s0# ->
case newArray# n# defval s0# of (# s1#, marr# #) -> (# s1#, Arr marr# #)
size :: Arr a -> Int
size (Arr a) = I# (sizeofMutableArray# a)
read :: Arr a -> Int -> IO a
read (Arr a) (I# n#) = IO $ \s0# ->
case readArray# a n# s0# of (# s1#, val #) -> (# s1#, val #)
write :: Arr a -> Int -> a -> IO ()
write (Arr a) (I# n#) val = IO $ \s0# ->
case writeArray# a n# val s0# of s1# -> (# s1#, () #)
|