Reputation: 83
The Haskell function
foo = zipWith ($) . repeat
does exactly the same as
map
but I cannot see why :-( Who can give an explanation? Thx a lot!
Upvotes: 8
Views: 128
Reputation: 62808
OK, so we have
foo = zipWith ($) . repeat
which is the same as
foo f = zipWith ($) (repeat f)
The repeat f
generates an infinite list of copies of f
. Then zipWith
uses the ($)
operator to apply each element of the [infinite copies of f
] list to each element of the incoming list. Which is what map
does.
Yes?
Upvotes: 14