[project @ 2001-08-22 11:45:06 by sewardj]
[ghc-hetmet.git] / ghc / tests / array / should_run / arr014.hs
1 -- !!! multi-dimensional arrays
2
3 module Main ( main ) where
4 import ST
5 import Array
6
7 type TwoD s = STArray s Int (STArray s Int Int)
8
9 setup :: ST s (TwoD s)
10 setup = let isz = 10
11             imax = isz - 1        
12             osz = 2
13             omax = osz - 1 in
14         do
15             -- gives : undefined reference to `IOBase_error_closure'
16 --          x <- newArray (0, omax) (error "uninitialised")
17             dmy <- newSTArray (0, imax) 0      
18             x <- newSTArray (0, omax) dmy
19             as <- (sequence . replicate osz) (newSTArray (0, imax) 6)
20             mapM_ (\(i,v) -> writeSTArray x i v) (zip [0..omax] as)
21             return x      
22
23 main :: IO ()
24 main = do
25          a <- stToIO setup
26          return ()