July 2023
Intermediate to advanced
670 pages
17h 13m
English
It’s possible to easily implement a reverse function using folds. Try to implement a function that will reverse a list using both foldl and foldr. Which one is simpler? why? Might one be more efficient than the other?
The zip function is a special case of a more general function available in Prelude called zipWith. The zipWith function combines two lists according to a function. Consider this implementation of zip in terms of zipWith:
| | λ let zip' = zipWith (,) |
| | λ zip' [1..5] [5,4..1] |
| | [(1,5),(2,4),(3,3),(4,2),(5,1)] |
Implement the zipWith function with and without using list comprehensions. Can you implement zipWith using foldl?
The concat function joins a list of ...
Read now
Unlock full access