Write a function min_max : int list -> int * int
that takes a non-empty list of numbers, and returns a pair (min, max) of the minimum and maximum of the numbers in the list.
Here is what I've written so far.
fun min_max (n : int list) =
if null n then NONE
else
let
fun max (n : int list) =
if null (tl n) then hd n
else
let
val mn = max (tl n)
in
if hd n > mn then hd n
else mn
end
fun min (n : int list) =
if null (tl n) then hd n
else
let
val mix = min (tl n)
in
if hd n < mix then hd n
else mix
end
in
SOME (min :: max)
end;