(* https://stackoverflow.com/questions/25839939/understanding-merge-sort-in-ml *) fun split [] = ([], []) | split [a] = ([a], []) | split (a::b::cs) = let val (m,n) = split cs in (a::m, b::n) end; fun merge ([], ys) = ys | merge (xs, []) = xs | merge (x::xs, y::ys) = if x