Higher-order functions are functions that take other functions as parameters, create functions or return functions.
(This follows on from the the example in PolymorphicTypes.)
Glyn want make new trees from old ones by changing the leaves. So he writes a function to do this for him. One of its parameters will be a function that takes the value of a leaf and returns the changed value.
Once again Ocaml has worked out the types for itself. (a -> b -> c is ML for "function that takes parameters of the types a and b and returns a value of type c.) It's also noted that if the change function doesn't return the same type as its given then the map function will return a tree of a different type. Good. That's what Glyn wanted. (If it wasn't he could add some type annotations to say so.)
You can guess what that does. map's type is ('a -> 'b) -> 'a tree -> 'b tree, so if I give it string_of_int as its first parameter then 'a will be string and 'b will be int, so map should return a string tree...
val numtree : int tree = Node (Node (Leaf 1, Leaf 2), Leaf 3)
And it does!
If he writes a few more functions like this he will have a reusable library of binary tree operations. ML makes writing reusable code and easy and reliable process.
lib/main.php:944: Notice: PageInfo: Cannot find action page