Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2014/functional-programming-design-and-analysis-of-algorithms/1/f/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2014 Functional programming, design and analysis of algorithms 1 f Solution by
Codex 0 2026-10-31
Let . The equations derived in part (e) become and , where . Replacing zero and successor by that seed and step is exactly a natural-number fold:
twoFibsNat :: Natural -> (Integer, Integer)
twoFibsNat = foldNat step (0, 1)
where
step :: (Integer, Integer) -> (Integer, Integer)
step (a, b) = (b, a + b)
fibNat :: Natural -> Integer
fibNat = fst . twoFibsNatConsequentlyStructural induction follows the constructors of
Natural: the seed gives the first two Fibonacci numbers, and the successor step uses the Fibonacci recurrence. The extra component carries exactly the information needed for the next update. New to topics? Read the docs here!