[project @ 1996-11-26 14:59:00 by dnt]
[nofib.git] / GHC_ONLY / bugs / sanders_array / Main-ORIG.hs
1 {-
2 From: Paul Sanders <psanders@srd.bt.co.uk>
3 To: partain
4 Subject: A puzzle for you
5 Date: Mon, 28 Oct 91 17:02:19 GMT
6
7 I'm struggling with the following code fragment at the moment:
8 -}
9
10 conv_list :: [a] -> [b] -> [[c]] -> Array (a,b) c -> Array (a,b) c
11 conv_list [] _ _ ar = ar
12 conv_list _ _ [] ar = ar
13 conv_list (r:rs) cls (rt:rts) ar
14 = conv_list rs cls rts ar'
15 where ar' = conv_elems r cls rt ar
16
17 conv_elems :: a -> [b] -> [c] -> Array (a,b) c -> Array (a,b) c
18 conv_elems row [] _ ar = ar
19 conv_elems _ _ [] ar = ar
20 conv_elems row (col:cls) (rt:rts) ar
21 = conv_elems row cls rts ar'
22 where ar' = ar // ((row,col) := rt)
23
24 ar_list = [[1,2,3],
25 [6,7,8],
26 [10,12,15]]
27
28 ar :: Array (Int, Int) Int
29 ar = conv_list [1..3] [1..3] ar_list init_ar
30 where init_ar = array ((1,1),(3,3)) []
31
32 main = appendChan stdout (show ar) abort done
33
34 {-
35 What it tries to do is turn a list of lists into a 2-d array in an incremental
36 fashion using 2 nested for-loops. It compiles okay on the prototype compiler
37 but gives a segmentation fault when it executes. I know I can define in the
38 array in one go (and I have done) but, for my piece of mind, I want to get this
39 way working properly.
40
41 Is it a bug in the prototype or is there a glaringly obvious error in my code
42 which I've been stupid to spot ????
43
44 Hoping its the latter,
45
46 Paul.
47 -}