[Haskell-cafe] List manipulation

Dmitri Pissarenko mailing-lists at dapissarenko.com
Wed Jan 26 11:39:42 EST 2005


Hello!

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.

If list1 is [1, 2, 100] and list2 is [2, 3, 500], then the result of the
operation I desire is [3, 5, 600].

I wrote this function

<function>
add2Img :: [Double] -> [Double] -> [Double]
add2Img summand1 summand2 = sum
	where sum = [ (x+y) | x <- summand1, y <- summand2 ]
</function>,

but I'm getting

[3.0,4.0,501.0,4.0,5.0,502.0,102.0,103.0,600.0]

instead of

[1, 2, 100].

What is wrong with the function above?

TIA

Dmitri Pissarenko
--
Dmitri Pissarenko
Software Engineer
http://dapissarenko.com


More information about the Haskell-Cafe mailing list