[Haskell-cafe] Re: zip3, zip4 ... -> zipn?

Brent Yorgey byorgey at gmail.com
Mon Aug 13 14:05:53 EDT 2007


On 8/11/07, Per Vognsen <per.vognsen at gmail.com> wrote:
>
> Applicative functors can indeed help:
>
>     (,,,) <$> [1,2,3] <*> [-1,0,1] <*> [1,1,1] <*> [0,2,6]
>
> You just use n-1 commas when you want the effect of zipn.


Actually, that's not quite right, since that uses the applicative functor
related to the list monad (so you get a list of 4-tuples of all possible
combinations, rather than a 4-way zip).  To get the zip behavior, you need
to add a ZipList constructor in front of all the lists, and then apply
getZipList at the end to extract.

-Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070813/11e236dd/attachment-0001.htm


More information about the Haskell-Cafe mailing list