module Main where import MArray import ST addArray :: (Ix ix, Num a) => STArray s ix a -> STArray s ix a -> STArray s ix a -> ST s () addArray v1 v2 v3 | b1 == b2 && b1 == b3 = mapM_ update (indices v1) | otherwise = error "Bounds mismatch in addArray" where b1 = bounds v1 b2 = bounds v2 b3 = bounds v3 update i = do x1 <- readArray v1 i x2 <- readArray v2 i writeArray v3 i (x1 + x2) testAddArray = do v1 <- newListArray (1,10) [0..10] v2 <- newListArray (1,10) [1..10] v3 <- newArray_ (1,10) addArray v1 v2 v3 getElems v3 main = do xs <- stToIO testAddArray print xs