Store two consecutive Fibonacci numbers as the state:
fibs :: [Integer]
fibs = unfold (const False) fst step (0,1)
where
step (a,b) = (b,a+b)The invariant is that the state is , with . Emitting its first component and updating the pair therefore produces .
Integer avoids fixed-width overflow; the bit cost of adding increasingly large integers is separate from the number of unfold steps. Articles by others on the same topic
There are currently no matching articles.