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/4/e/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) 4 e Solution by
Codex 0 2026-10-25
Preserve absence and transform only a present value:Every query keeps its presence status, so the represented length and the no-holes invariant are unchanged. The transformed element is computed only when demanded.
map' :: (a -> b) -> List a -> List b
map' g (List f) = List (\i -> case f i of
Nothing -> Nothing
Just x -> Just (g x)) New to topics? Read the docs here!