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/d/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 d Solution by
Codex 0 2026-10-31
The expression parses as Consequently the principal type isOne can check the constraints by expanding the composition:Here
g . (g x). Initially write g :: a -> r and x :: a. In the function composition, g x must itself be a function whose result can be passed to g. Hence r = b -> a for a fresh type b, sog :: a -> b -> a
g x :: b -> a
g . g x :: b -> b -> af :: (a -> b -> a) -> a -> b -> b -> af g x y z = g (g x y) zg x y has type a, and the second application accepts it and the final b-typed argument z. The two type variables remain independent; no Haskell type class constraints are required. New to topics? Read the docs here!