I tried to make an iterative / tail-recursive version of the function to calculate the number n th of the Fibonacci sequence, but I get parse error (possibly incorrect indentation). Why is this happening? The code I'm using is:
fib n
| n < 2 = n
| otherwise = fibhelper 0 1 2 n
where fibhelper a b curr num
| curr == num = a + b
| curr < num = fibhelper b (a+b) (curr+1) num
To be clear, I am trying to understand the error - why this is happening, how it should be fixed - and not try to implement it effectively fib(I understand the popular implementation zipWith here , for example).
Thank!
source
share