(* function to merge two lists sorted in ascending order *) fun merge ([],x) = x | merge (x,[]) = x | merge (l1 as (h1::t1),l2 as (h2::t2)) = (**) if h1 < (h2: int) (***) then h1::(merge (t1,l2)) else if h2 < h1 then h2::(merge (l1,t2)) else (* h1 = h2 *) h1::(merge (t1,t2)) ; (* NOTES *) (** "X as Pattern" is a way of giving a name to the parts of an object (using Pattern) and the whole object at the same time. In this case, l1 is the name of the first argument, h1 is the name of the head of l1, and t1 is the name of the tail of l1. *) (*** inequality is overloaded (reals, integers) so we need to specify a type. Later we'll see how to use functors to overcome this. *)