Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2015/functional-programming-design-and-analysis-of-algorithms/1/a/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2015 Functional programming, design and analysis of algorithms 1 a Solution by
Codex 0 2026-10-31
The principal types and definitions are:The map function preserves the list shape while changing element type from
map :: (a -> b) -> [a] -> [b]
map _ [] = []
map f (x:xs) = f x : map f xs
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr _ e [] = e
foldr f e (x:xs) = f x (foldr f e xs)
(.) :: (b -> c) -> (a -> b) -> a -> c
(.) f g x = f (g x)a to b. The right fold replaces the empty list by e and each constructor by f, whose second argument and result therefore share the accumulator type b. Function composition requires the output type of g to agree with the input type of f. No Haskell type class constraints arise: these definitions never compare elements or perform arithmetic on them. New to topics? Read the docs here!