1 --!!! mutable Double array test (ncg test)
3 module Main ( main ) where
5 import PrelBase --ghc1.3
12 main = --primIOToIO (newDoubleArray (0,1) >>= \ arr -> readDoubleArray arr 0) >>= print
16 test_doubles :: String
20 shows (lookup_range arr# 42# 416#) "\n"
22 f :: Int -> ByteArray Int
26 -- allocate an array of the specified size
27 newDoubleArray (0, (size-1)) >>= \ arr# ->
29 -- fill in all elements; elem i has "i * pi" put in it
30 fill_in arr# 0# (size# -# 1#) >>
33 freezeDoubleArray arr#
36 fill_in :: MutableByteArray s Int -> Int# -> Int# -> ST s ()
38 fill_in arr_in# first# last#
39 = if (first# ># last#)
41 else writeDoubleArray arr_in# (I# first#) ((fromInt (I# first#)) * pi) >>
42 fill_in arr_in# (first# +# 1#) last#
44 lookup_range :: ByteArray Int -> Int# -> Int# -> [Double]
45 lookup_range arr from# to#
48 else (indexDoubleArray arr (I# from#))
49 : (lookup_range arr (from# +# 1#) to#)