## Fibonacci series one-liner in Haskell

Here’s a beautiful example of why Haskell is the most advanced programming language on the planet – a one-line definition of the *entire* fibonacci series:

`fiblist = 0 : 1 : (zipWith (+) fiblist (tail fiblist))`

Stunning. Note that that is *not* a function to calculate the nth fibonacci number: it really is a definition of the entire series. If you want the nth fibonacci number, look up the nth element of that list. Let’s see you do that in Java! (Or C#)

(Via the introductory series on Haskell at the rather good Good Math, Bad Math (more on the author here).)

I was going to post a really long comment, but I decided to put it on my blog instead.

Cultural note: coding up the fibonacci series is a standard greeting for newcomers in

#haskell For example:

:-)

I presume for the second to last one you mean:

Which is more or less equivalent (in terms of how it works) to the zipWith implementation. I got caught out with the < too – you have to html-escape it. (More “must use HTML” than “may use HTML” really :)

Edit 2007.01.21— not any more! -gimboSame thing but in scheme

Here it is in Perl 6:

`my @fiblist = 0, 1 ... { $^a + $^b };`

The Perl 6 example from 2008 is now out of date. Here’s an updated version.

Or you could make it a little more concise:

And if you want to golf it: