I have this code that unites two lists:
let rec union list1 list2 =
match list2 with
| [] -> list1
| x::xs when mem x list1 -> union list1 xs
| x::xs -> x::(union list1 xs)
However, this doesn't give me the result I would like; I want the result to be in order with the smallest first. How would I go about doing this?