In ML, foldl and foldr both have this type. fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b How can we derive each of these two functions from this single type signature? Start with the simplest function that has this signature, the function that only uses the first item in a non-empty list. Call this simple function fold. fun fold h x [] = x | fold h x (y::_) = h (y, x); (* does not traverse the input list *) The main body of the function is a single application of h to the pair of y and x. We want to generalize this in two ways in order to get foldl and foldr. Look at h (y, x) and look for a way in which it has "two sides" that can be generalized upon. In the application of h, there are two parameters, y and x. We might generalize fold two ways by replacing either y or x in the application of h, but that does not get us to both foldl and foldr. Notice that h has a type 'b parameter and it has a type 'b return value. These are the "two sides" of h (y, x) that will lead us to foldl and foldr. First, let's replace the x, the type 'b parameter in h (y, x) with a recursive call to fold (since fold has a type 'b return value) giving fold the x along with the rest of the list. This turns out to be foldr. fun fold h x [] = x | fold h x (y::ys) = h (y, fold h x ys); (* foldr *) Second, let us use the type 'b return value of h (y, x) in a recursive call to fold in the place of fold's type 'b parameter. This turns out to be foldl. fun fold h x [] = x | fold h x (y::ys) = fold h (h (y, x)) ys; (* foldl *)