我正在做一个练习,其中给出了两个时间戳,我必须找到哪个大。这个程序是用 SML 编写的。所以我想出了这个程序....
type triple = {int,int,string};
val record1 = (11,45,"PM");
val record2 = (2,13,"AM");
fun timerrecord(record1:triple,record2:triple)=
let val (hour1:int,min1:int,f1:string) = record1;
val (hour2:int,min2:int,f2:string) = record2
in
if (f1= "AM") andalso (f2="PM") then "t1 comes First"
else if(f1 = "PM") andalso (f2="AM") then "t2 comes First"
else if (hour1 < hour2) then "t1 comes First"
else if (hour1 > hour2) then "t2 comes First"
else if (min1 < min2) then "t1 comes First"
else "t2 comes First";
上面的程序没有作为一个整体执行,但个别逻辑是因为元组。我无法充分利用元组来比较 2 个时间戳。另外我想知道如何访问元组,就好像它是已知的那样我们可以很容易地解决这个问题。提前致谢。