[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / interpreter / test / runtime / r009.hs
diff --git a/ghc/interpreter/test/runtime/r009.hs b/ghc/interpreter/test/runtime/r009.hs
new file mode 100644 (file)
index 0000000..b0f36a7
--- /dev/null
@@ -0,0 +1,26 @@
+--!!! Some simple examples using arrays.
+
+module ArrayEx where
+import Array
+
+-- Some applications, most taken from the Gentle Introduction ... -------------
+
+timesTable :: Array (Int,Int) Int
+timesTable  = array ((1,1),(10,10)) [ ((i,j), i*j) | i<-[1..10], j<-[1..10] ]
+
+fibs n = a where a = array (0,n) ([ (0,1), (1,1) ] ++
+                                  [ (i, a!(i-2) + a!(i-1)) | i <- [2..n] ])
+
+wavefront n = a where a = array ((1,1),(n,n))
+                             ([ ((1,j), 1) | j <- [1..n] ] ++
+                              [ ((i,1), 1) | i <- [2..n] ] ++
+                              [ ((i,j), a!(i,j-1) + a!(i-1,j-1) + a!(i-1,j))
+                                           | i <- [2..n], j <- [2..n] ])
+
+listwave n = [ [wf!(i,j) | j <- [1..n]] | i <- [1..n] ]
+             where wf = wavefront n
+
+eg1 :: Array Integer Integer
+eg1  = array (1,100) ((1, 1) : [ (i, i * eg1!(i-1)) | i <- [2..100] ])
+
+-------------------------------------------------------------------------------