我不知道,我怎麼能找到在列表中的最早日期:獲取最小元素(運營商是不是函數[tycon不匹配])
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
你試過了嗎?它說錯誤:運算符不是函數[tycon不匹配] - the_oldest_date([(2005,1,11),(2006,1,11)]) –
加載文件到sml後得到:val the_oldest_date = fn: (int * int * int)list - >(int * int * int)option val it =():unit – user987339
After:the_oldest_date([(2005,1,11),(2006,1,11)]) ;我得到:val it = SOME(2005,1,11):(int * int * int)選項 – user987339