Alex,
your older_date function is not working right. You didn't consider two dates that have same year and/or month (ie. (1,1,1) and (1,1,2)). And finally this function should return bool
not a (int * int * int)
.
Finding a maximum is a bit trickier, so you should try to find the maximum of a list tail and then compare it with a head.
I hope this helps. And my code is:
fun the_oldest_date(date_list : (int * int * int) list) : (int * int * int) option =
let
fun older_date(date1:(int * int * int) , date2:(int * int * int)) : bool =
if #1 date1 < #1 date2
then true
else if #1 date1 = #1 date2
then if #2 date1 < #2 date2
then true
else if #2 date1 = #2 date2
then if #3 date1 < #3 date2
then true
else false
else false
else false
in
if null date_list
then NONE
else
let
val prevMax = the_oldest_date(tl date_list)
in
if prevMax = NONE
then SOME(hd date_list)
else if older_date(hd date_list, valOf prevMax)
then SOME(hd date_list)
else prevMax
end
end