2 From: Paul Sanders <psanders@srd.bt.co.uk>
4 Subject: A puzzle for you
5 Date: Mon, 28 Oct 91 17:02:19 GMT
7 I'm struggling with the following code fragment at the moment:
13 conv_list :: (Ix a, Ix b) => [a] -> [b] -> [[c]] -> Array (a,b) c -> Array (a,b) c
14 conv_list [] _ _ ar = ar
15 conv_list _ _ [] ar = ar
16 conv_list (r:rs) cls (rt:rts) ar
17 = conv_list rs cls rts ar'
18 where ar' = conv_elems r cls rt ar
20 conv_elems :: (Ix a, Ix b) => a -> [b] -> [c] -> Array (a,b) c -> Array (a,b) c
21 conv_elems row [] _ ar = ar
22 conv_elems _ _ [] ar = ar
23 conv_elems row (col:cls) (rt:rts) ar
24 = conv_elems row cls rts ar'
25 where ar' = ar // [((row,col), rt)]
27 ar :: Array (Int, Int) Int
28 ar = conv_list [(1::Int)..(3::Int)] [(1::Int)..(3::Int)] ar_list init_ar
29 where init_ar = array (((1::Int),(1::Int)),((3::Int),(3::Int))) []
32 ar_list :: [[Int]] -- WDP
37 main = putStr (show ar)
40 What it tries to do is turn a list of lists into a 2-d array in an incremental
41 fashion using 2 nested for-loops. It compiles okay on the prototype compiler
42 but gives a segmentation fault when it executes. I know I can define in the
43 array in one go (and I have done) but, for my piece of mind, I want to get this
46 Is it a bug in the prototype or is there a glaringly obvious error in my code
47 which I've been stupid to spot ????
49 Hoping its the latter,