[Haskell-cafe] Parse text difficulty

Tomasz Zielonka tomasz.zielonka at gmail.com
Thu Dec 9 10:57:24 EST 2004


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.

Best regards,
Tomasz


More information about the Haskell-Cafe mailing list