Tomasz Zielonka writes:
On Thu, Dec 09, 2004 at 10:02:39AM -0500, Jan-Willem Maessen - Sun Labs East wrote:
And I thought that most programmers used "zipWith", which has to be prefix.
You can also use zipWith to simulate zipN, for any N (however, the following code uses infix notation):
Here's my favorite method, which I picked up from a paper whose title I have forgotten: Prelude> let zipWithN = (.repeat) Prelude> let succ d f x = d (zipWith ($) f x) Prelude> let zero = id Prelude> let one = succ zero Prelude> let two = succ one Prelude> :t zipWithN two zipWithN two :: forall b b1 b2. (b -> b1 -> b2) -> [b] -> [b1] -> [b2] Prelude> zipWithN two (,) [1..] (words "Haskell is great") [(1,"Haskell"),(2,"is"),(3,"great")] Prelude> let three = succ two Prelude> :t zipWithN three zipWithN three :: forall b b1 b2 b3. (b -> b1 -> b2 -> b3) -> [b] -> [b1] -> [b2] -> [b3] Prelude> :t zipWithN (succ three) zipWithN (succ three) :: forall b b1 b2 b3 b4. (b -> b1 -> b2 -> b3 -> b4) -> [b] -> [b1] -> [b2] -> [b3] -> [b4] Note that zipWithN zero == repeat and zipWithN one == map -- David Menendez <zednenem@psualum.com> | "In this house, we obey the laws <http://www.eyrie.org/~zednenem> | of thermodynamics!"