summaryrefslogtreecommitdiff
path: root/testsuite/tests/programs/sanders_array
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/programs/sanders_array')
-rw-r--r--testsuite/tests/programs/sanders_array/Main.hs52
-rw-r--r--testsuite/tests/programs/sanders_array/Makefile3
-rw-r--r--testsuite/tests/programs/sanders_array/sanders_array.stdout1
-rw-r--r--testsuite/tests/programs/sanders_array/test.T6
4 files changed, 62 insertions, 0 deletions
diff --git a/testsuite/tests/programs/sanders_array/Main.hs b/testsuite/tests/programs/sanders_array/Main.hs
new file mode 100644
index 0000000000..d5a2b29d12
--- /dev/null
+++ b/testsuite/tests/programs/sanders_array/Main.hs
@@ -0,0 +1,52 @@
+{-
+From: Paul Sanders <psanders@srd.bt.co.uk>
+To: partain
+Subject: A puzzle for you
+Date: Mon, 28 Oct 91 17:02:19 GMT
+
+I'm struggling with the following code fragment at the moment:
+-}
+
+import Data.Array -- 1.3
+import Data.Ix -- 1.3
+
+conv_list :: (Ix a, Ix b) => [a] -> [b] -> [[c]] -> Array (a,b) c -> Array (a,b) c
+conv_list [] _ _ ar = ar
+conv_list _ _ [] ar = ar
+conv_list (r:rs) cls (rt:rts) ar
+ = conv_list rs cls rts ar'
+ where ar' = conv_elems r cls rt ar
+
+conv_elems :: (Ix a, Ix b) => a -> [b] -> [c] -> Array (a,b) c -> Array (a,b) c
+conv_elems row [] _ ar = ar
+conv_elems _ _ [] ar = ar
+conv_elems row (col:cls) (rt:rts) ar
+ = conv_elems row cls rts ar'
+ where ar' = ar // [((row,col), rt)]
+
+ar :: Array (Int, Int) Int
+ar = conv_list [(1::Int)..(3::Int)] [(1::Int)..(3::Int)] ar_list init_ar
+ where init_ar = array (((1::Int),(1::Int)),((3::Int),(3::Int))) []
+
+
+ar_list :: [[Int]] -- WDP
+ar_list = [[1,2,3],
+ [6,7,8],
+ [10,12,15]]
+
+main = putStrLn (show ar)
+
+{-
+What it tries to do is turn a list of lists into a 2-d array in an incremental
+fashion using 2 nested for-loops. It compiles okay on the prototype compiler
+but gives a segmentation fault when it executes. I know I can define in the
+array in one go (and I have done) but, for my piece of mind, I want to get this
+way working properly.
+
+Is it a bug in the prototype or is there a glaringly obvious error in my code
+which I've been stupid to spot ????
+
+Hoping its the latter,
+
+Paul.
+-}
diff --git a/testsuite/tests/programs/sanders_array/Makefile b/testsuite/tests/programs/sanders_array/Makefile
new file mode 100644
index 0000000000..9101fbd40a
--- /dev/null
+++ b/testsuite/tests/programs/sanders_array/Makefile
@@ -0,0 +1,3 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
diff --git a/testsuite/tests/programs/sanders_array/sanders_array.stdout b/testsuite/tests/programs/sanders_array/sanders_array.stdout
new file mode 100644
index 0000000000..d3405a74e2
--- /dev/null
+++ b/testsuite/tests/programs/sanders_array/sanders_array.stdout
@@ -0,0 +1 @@
+array ((1,1),(3,3)) [((1,1),1),((1,2),2),((1,3),3),((2,1),6),((2,2),7),((2,3),8),((3,1),10),((3,2),12),((3,3),15)]
diff --git a/testsuite/tests/programs/sanders_array/test.T b/testsuite/tests/programs/sanders_array/test.T
new file mode 100644
index 0000000000..03c4d4eece
--- /dev/null
+++ b/testsuite/tests/programs/sanders_array/test.T
@@ -0,0 +1,6 @@
+
+test('sanders_array',
+ [skip_if_fast, extra_clean(['Main.hi', 'Main.o'])],
+ multimod_compile_and_run,
+ ['Main', ''])
+