1 -- !!! mutable Double array test (ncg test)
3 module Main ( main ) where
5 import PrelBase --ghc1.3
14 main = --primIOToIO (newDoubleArray (0,1) >>= \ arr -> readDoubleArray arr 0) >>= print
18 test_doubles :: String
22 shows (lookup_range arr# 42# 416#) "\n"
24 f :: Int -> ByteArray Int
28 -- allocate an array of the specified size
29 newDoubleArray (0, (size-1)) >>= \ arr# ->
31 -- fill in all elements; elem i has "i * pi" put in it
32 fill_in arr# 0# (size# -# 1#) >>
35 freezeDoubleArray arr#
38 fill_in :: MutableByteArray s Int -> Int# -> Int# -> ST s ()
40 fill_in arr_in# first# last#
41 = if (first# ># last#)
43 else writeDoubleArray arr_in# (I# first#) ((fromInt (I# first#)) * pi) >>
44 fill_in arr_in# (first# +# 1#) last#
46 lookup_range :: ByteArray Int -> Int# -> Int# -> [Double]
47 lookup_range arr from# to#
50 else (indexDoubleArray arr (I# from#))
51 : (lookup_range arr (from# +# 1#) to#)