Tomasz Zielonka wrote: > 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): > > Prelude> let l = words "Haskell is great" > Prelude> let zwApply = zipWith ($) > Prelude> repeat (,,) `zwApply` [1..] `zwApply` l `zwApply` map length l > [(1,"Haskell",7),(2,"is",2),(3,"great",5)] > Prelude> map (,,) l `zwApply` [1..] `zwApply` map length l > [("Haskell",1,7),("is",2,2),("great",3,5)] > > I found it useful recently, when I needed zip functions for Trees - this way I > didn't have to define functions for 3 trees, 4 trees, and so on.
Note also that: repeat f `zwApply` xs = map f xs When cooking up my own collection-y things (including splittable supplies, for example), I generally provide fmap and an equivalent of zwApply (a generic repeat is not quite so simple or useful). It's a nice little idiom, and a recommend it highly. -Jan-Willem Maessen > > Best regards, > Tomasz > _______________________________________________ > Haskell-Cafe mailing list > [EMAIL PROTECTED] > http://www.haskell.org/mailman/listinfo/haskell-cafe _______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe