我想知道,如何在列表中找到最旧的日期:
fun the_oldest_date(date_list: (int * int * int) list) =
let
(*it might be useful*)
fun older_date(date1: (int * int * int), date2: (int * int * int)) =
if #1 date1 < #1 date2 andalso
#2 date1 < #2 date2 andalso
#3 date1 < #3 date2
then date1
else date2
in
if null date_list
then NONE
else SOME older_date(hd date_list, the_oldest_date(tl date_list))
end
我不想在这里使用任何库函数,只使用递归和标准 ML 工具。我得到了错误
Error: operator is not a function [tycon mismatch]
operator: ((int * int * int) * (int * int * int) -> int * int * int) option
in expression:
(SOME older_date) (hd date_list,the_oldest_date (tl date_list))
/usr/lib/smlnj/bin/sml: Fatal error -- Uncaught exception Error with 0