
26 Jan
2005
26 Jan
'05
11:47 a.m.
Dmitri,
I have two lists of Double with equal length and want to create a third one, in which each element is the sum of the corresponding element of the first list and the second list.
<function> add2Img :: [Double] -> [Double] -> [Double] add2Img summand1 summand2 = sum where sum = [ (x+y) | x <- summand1, y <- summand2 ] </function>,
What is wrong with the function above?
You're performing a point-wise addition, but instead add each element of the second list to each element of the first list, yielding n * m sums for list lengths n and m. The function you're looking for is written add2Img = zipWith (+) HTH, Stefan