There are a few cool ways to do it, first the simplest
fib::Int->Int
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
fibList n = map fib [1..n]
or we can merge this into one
fib::Int->[Int]
fib 0 = [0]
fib 1 = [1, 0]
fib n = (head (fib (n-1)) + head (fib (n-2))) : fib (n-1)
So here we're just combining the list building with the recursion. Now we take a step towards the crazy
fib n = take n fiblist
where fiblist = 0:1:(zipWith (+) fiblist (tail fiblist))
Here fiblist
is an infinite list of Fibonacci numbers. All we're doing is grabbing the appropriate amount. This is possible because Haskell is "lazy". If you're new to Haskell, just smile and nod.
Lastly, for kicks and giggles
fib = flip take . fix $ \f -> 0 : 1 : (zipWith (+) f (tail f))
This is the same of above except point-free and with a fixed point instead of recursion.
Again if you're new to haskell, the first 2 are a little easier to grok, come back to the last 2 in a few weeks :)