I\'m learning Haskell, and came across the following code:
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
which I\'m having a bit of trouble p
Let's take a look at definition of zipWith
zipWith f (x:xs) (y:ys) = f x y : zipWith xs ys
Our fibs is:
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
For take 3 fibs substituting the definition of zipWith and xs = tail (x:xs) we get
0 : 1 : (0+1) : zipWith (+) (tail fibs) (tail (tail fibs))
For take 4 fibs substituting once more we get
0 : 1 : 1 : (1+1) : zipWith (+) (tail (tail fibs)) (tail (tail (tail fibs)))
and so on.