exception MinF; datatype 'a F = A of 'a F list | B of 'a | C
Write a function called minF
to
return the minimal value of type 'a
in a
data structure of type 'a F
, using the
function min
passed as a parameter to
minF
. min
has to be used to choose the smaller one
out of two values. minF
should return
the exception MinF
if f
contains no value of type 'a
at all.
(* minF : ('a * 'a -> 'a) -> 'a F -> 'a minF min f = the smallest value of type 'a in f, according to min, or the exception MinF, if f has no value of type 'a at all *)You are allowed to define auxiliary functions.
(minF Int.min C handle MinF => 999) = 999; minF Int.min (B 3) = 3; (minF Int.min (A[]) handle MinF => 0) = 0; (minF Int.min (A[A[],C,A[],A[],C]) handle MinF => ~999) = ~999; minF Real.min (A[B 5.4,A[],C,B ~13.6,B 7.7]) = ~13.6; minF Int.min (A[B 5,A[B ~5,B 765,B ~875],A[],A[B 7,A[],B 76,C]]) = ~875; minF (fn (x,y) => chr(Int.min(ord x, ord y))) (A[B#"c",C,A[],B#"k",B#"i"]) = #"c";