Solution

ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2017/functional-programming-design-and-analysis-of-algorithms-resit/4/e/solution

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.

New to topics? Read the docs here!