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:
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
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
)
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)) []
32 main
= appendChan
stdout (show ar
) abort done
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
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 ????
44 Hoping its the latter,