1 --!!! Some simple examples using arrays.
6 -- Some applications, most taken from the Gentle Introduction ... -------------
8 timesTable :: Array (Int,Int) Int
9 timesTable = array ((1,1),(10,10)) [ ((i,j), i*j) | i<-[1..10], j<-[1..10] ]
11 fibs n = a where a = array (0,n) ([ (0,1), (1,1) ] ++
12 [ (i, a!(i-2) + a!(i-1)) | i <- [2..n] ])
14 wavefront n = a where a = array ((1,1),(n,n))
15 ([ ((1,j), 1) | j <- [1..n] ] ++
16 [ ((i,1), 1) | i <- [2..n] ] ++
17 [ ((i,j), a!(i,j-1) + a!(i-1,j-1) + a!(i-1,j))
18 | i <- [2..n], j <- [2..n] ])
20 listwave n = [ [wf!(i,j) | j <- [1..n]] | i <- [1..n] ]
21 where wf = wavefront n
23 eg1 :: Array Integer Integer
24 eg1 = array (1,100) ((1, 1) : [ (i, i * eg1!(i-1)) | i <- [2..100] ])
26 -------------------------------------------------------------------------------