I was just starting to study Haskell and how the exercise got into the Project Euler problem, where the Fibonacci numbers were. My current method is this function, which creates a new list with the following element:
fib :: (Integral a) => [a] -> [a] fib xs@ (x1:x2:_) = (x1+x2) : xs
I found an iterate
function that returns a function on the result. However, the result is a list of lists, [[2,1],[3,2,1],[5,3,2,1],..]
. What is the iterate
alternative when I'm not interested in intermediate results? I want to make takeWhile
with a condition for the last generated number. Is it not at all to think about it?
(I saw better / shorter / faster ways to generate a Fibonacci sequence, so I am not looking for feedback on the fib
function, but I would like to make it work, a suboptimal method or not)
source share