[Haskell-cafe] List manipulation

Jules Bean jules at jellybean.co.uk
Wed Jan 26 11:50:51 EST 2005


On 26 Jan 2005, at 16:39, Dmitri Pissarenko wrote:

> Hello!

Hi Dmitri.

Have a browse around the haskell wiki! There's loads of interesting 
information and example code there...

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


> [3.0,4.0,501.0,4.0,5.0,502.0,102.0,103.0,600.0]
>
> instead of
>
> [1, 2, 100].
>

[(x+y) | x <- summand1, y <- summand2] means *all* possible sums x+y 
with x taken from the first list and y from the second. This is the 
nature of list comprehensions.

You rather want 'zipWith'.  Documentation at:

http://www.haskell.org/ghc/docs/latest/html/libraries/base/GHC.List.html

...along with lots of other funky list processing stuff.

Jules



More information about the Haskell-Cafe mailing list