September 2017
Beginner to intermediate
396 pages
9h 46m
English
The preceding implementation looks deceptively simple, and it works! This is one of the highlights of Haskell. It provides a very elegant language construct to write such compact and meaningful programs in.
The heart of fiblist is the use of the zipWith function. The zipWith has the following signature:
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
The zipWith function takes a function f and two lists. The zipWith function takes out an element from each list and applies the funcion f on these two elements. The zipWith function recursively continues this operation until either of the input lists are exhausted. In fact, zipWith is implemented in Prelude as follows:
zipWith f [] _ = [] -- Either input is empty, the result is ...
Read now
Unlock full access