Simpler Fibonacci function
Brian Berns
Berns@rdacorp.com
Tue, 5 Feb 2002 12:40:31 -0500
I am new to functional programming and teaching myself Haskell. The
canonical Haskell "fib" function (e.g. as presented in the "Gentle"
tutorial) is:
fib = 1 : 1 : [ a+b | (a,b) <- zip fib (tail fib) ]
This seems, to be polite, a bit overly complex. By comparison, here
is a simpler version:
fib x y = x : fib y (x+y)
For example, fib 1 1 => [1,1,2,3,5,8,13,21,...].
Is there a reason why the canonical fib function is so complex? If
not, would it be possible to use a simpler version in the tutorial?
Thanks.
-- Brian