简体   繁体   中英

Who can explain this Haskell function?

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!

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM