
18 Oct
2011
18 Oct
'11
12:19 p.m.
Hi, so I wrote this function to add two vectors represented as lists: add a b = add' a b [] where add' [] [] s = s add' (a:as) (b:bs) s ++ [a+b] OK, I tried this in ghci:
add [1,2,3] [1,2,3] [6,4,2]
Hm, I expected the result to be [2,4,6], of course, since the currently added components always go to the end of the resulting vector. I then changed the last term in add' to [a+b] ++ s , but still
add [1,2,3] [1,2,3] [6,4,2]
Can anyone explain this behavior to me. I think there should be some change in the result, no? Alex