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