-- $Id: ary3.ghc,v 1.2 2001/06/01 17:56:49 doug Exp $ -- http://www.bagley.org/~doug/shootout/ -- TBD: try rewrite with STUArray or IOUArray module Main where import IArray import System make_x :: Int -> UArray Int Int make_x len = array (1,len) [(i, i) | i <- [1..len]] make_y0 :: Int -> UArray Int Int make_y0 len = array (1,len) [(i, 0) | i <- [1..len]] add_array :: Int -> UArray Int Int -> UArray Int Int -> UArray Int Int add_array 0 a b = b add_array len a b = array (1,len) [(i, ((a ! i) + (b ! i))) | i <- [1..len]] add_arrays_n :: Int -> Int -> UArray Int Int -> UArray Int Int -> UArray Int Int add_arrays_n 0 len a b = b add_arrays_n n len a b = add_arrays_n (n-1) len a (add_array len a b) ary3 :: Int -> IO () ary3 len = do putStr (show (y ! 1)) ; putStr " " ; putStrLn (show (y ! len)) where y = add_arrays_n 1000 len (make_x len) (make_y0 len) main = do ~[n] <- getArgs ary3 (read n::Int)