[Haskell-beginners] generating by mapping

Tim Perry perry2of5 at yahoo.com
Tue Mar 16 14:40:33 EDT 2010


Stephen's version is cleaner, but this works too:
map (\(x, y) -> Stuff x y) $ zip nums strs




----- Original Message ----
From: Stephen Tetley <stephen.tetley at gmail.com>
To: Szilveszter Juhos <szilva.juhos at gmail.com>
Cc: Beginners at haskell.org
Sent: Tue, March 16, 2010 2:09:51 AM
Subject: Re: [Haskell-beginners] generating by mapping

Hi Szilveszter

zipWith is probably what you are after...

> zipWith Stuff nums strs
[Stuff {aNum = 123, anStr = "qwe"},Stuff {aNum = 321, anStr =
"asd"},Stuff {aNum = 345, anStr = "zxc
"}]

Note zipWith (and the function zip which it generalizes) go 'short' -
i.e. if one of the input lists is shorter than the other - the size of
the result list will the size of of the shorter one:


> zipWith Stuff [1] strs
[Stuff {aNum = 1, anStr = "qwe"}]


Best wishes

Stephen
_______________________________________________
Beginners mailing list
Beginners at haskell.org
http://www.haskell.org/mailman/listinfo/beginners



More information about the Beginners mailing list