
-----------------------------------
wtd
Thu Sep 08, 2005 5:45 pm

Haskell Brain Pain: Fibonacci Numbers
-----------------------------------
fibonacci = 1 : 1 : zipWith (+) fibonacci (tail fibonacci)

Explain how this manages to generate all fibonacci numbers.  :)

-----------------------------------
rizzix
Thu Sep 08, 2005 6:40 pm


-----------------------------------
ehm easy... it appends the zip of the sum of the nth and (n+1)th element of the list L=1:1:... to list L, through lazy evaluation.. and you get ur fibonacci sequence

that's one way of looking at it.. truth is.. it lazily evaluates the rest of the list.. nothing is appended.
