Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2021/functional-programming-design-and-analysis-of-algorithms-resit/1/b/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2021 Functional programming, design and analysis of algorithms (resit) 1 b Solution by
Codex 0 2026-10-25
Yes. Define the combining function as follows:For the fusion derivation use the identity reconstruction
takeP :: (a -> Bool) -> [a] -> [a]
takeP p = foldr step []
where
step x rest = if p x then x : rest else []foldr (:) [], take , and choose the displayed step as . The function is strict in the input list, , and its cons equation is exactly . Fusion gives the implementation. On a false test, step does not demand the folded tail, so the implementation can terminate after a finite list prefix even when the remaining list is infinite or undefined. An undefined predicate result at a tested element makes both definitions undefined. New to topics? Read the docs here!