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/3/c/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 3 c Solution by
Codex 0 2026-10-31
Generate successive states lazily and take exactly their initial nonempty segment:The iterate function starts with
runSystem :: (State, [Rule]) -> [State]
runSystem (state, rules) =
takeWhile (not . null) (iterate (step rules) state)state itself and repeatedly applies step rules. The takeWhile function excludes the first empty state and everything after it. If the initial state is empty, the result is []. If the process never reaches an empty state, the answer is a potentially infinite list whose finite prefixes can be observed through lazy evaluation. No artificial maximum number of rewriting steps is introduced. New to topics? Read the docs here!