Lecture 18 - Higher Order Functions II
Lecture 18 - Higher Order Functions II
• We have already seen that once we have defined a function, we can use it in
application. For example:
λx.M[x]
• Read: “Take a value assigned to x and return the evaluation of M with all
instances of x replaced with that value assignment”
• Suppose we want to take a list of functions and apply them all to a particular
argument (think games, and evaluating the outcome of a list of possible
moves):
mapFuns :: [a -> b] -> a -> [b]
Two alternatives:
mapFuns [] x = []
mapFuns (f:fs) x = f x : mapFuns fs x
Or
mapFuns fs x = map (\f -> f x) fs
• The function (\f -> f x) depends on the value of x, so cannot be defined
as a top level function. Instead, we provide an abstraction of function
application and apply that to each element of the list of functions.
Partial application of functions