Solution

ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2003/functional-programming-data-structures-and-algorithms-procedural-programming-and-digital-hardware/2/b/solution

A right fold replaces the empty list by a seed and each cons by an application of the combining function:
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr op e [] = e
foldr op e (x:xs) = op x (foldr op e xs)
For example, foldr op e [a,b,c] = op a (op b (op c e)). The concise defining law is

New to topics? Read the docs here!