let rec traverse combine action seed = function
| [] -> seed
| x :: xs -> combine (action x) (traverse combine action seed (xs));;
let comb x y = x :: y;;
let mult x = x * x;;
let mapsquare = traverse comb mult [];;
mapsquare [1; 5; 7; -2];;
let comb x y = x + y;;
let act x = 1;;
let count x = (traverse comb act 0) x;;
(* tree type and two sample trees *)
type 'a tree = Empty | Node of 'a * 'a tree * 'a tree;;
let intTree = Node (5, Node (3, Empty, Empty),
Node (6, Node (7, Empty, Empty), Empty));;
let strTree = Node ("apples", Empty, Node ("bananas",
Node ("oranges", Empty, Node ("grapes", Empty, Empty)), Empty));;

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.