Hi,
Problem: I would like to generate an infinite list of Fibonacci numbers. Although the below code does not work.
fibs :: [Integer]
fibs = 0 : 1 : [ n | x <-[2..], let n = ((fibs !! x-1) + (fibs !! x-2))]
Thought: I'm assuming that I'm ignorant on how ranges/generators work with a list comprehension, which is why this code is not working.
ghci output:
*Main> fibs !! 0
1
*Main> fibs !! 1
2
*Main> fibs !! 2
When I try and access the third element in the list ghci simply stalls.
Can someone please give me a little more insight on why my code is not working.
Thanks in advance.
drjoliv