2

我是 ML 编程的新手,我有一个作业要编写一个函数 is_older,它需要两个日期并评估为真或假。如果第一个参数是第二个参数之前的日期,则它的计算结果为 true。
(如果两个日期相同,则结果为假。)

val is_older = fn : (int * int * int) * (int * int * int) -> bool // Binding Like

我试过这个(使用New Jersy cmd prompt的SML)

fun is_older((y1,m1,d1),(y2,m2,d2))= if (y1<y2) then true 
else if (y1=y2 andalso m1<m2) then true 
else if (y1=y2 andalso m1=m2 andalso d1<d2) then true;

它给出了错误

Error syntax error: deleting SEMICOLON ID 
4

2 回答 2

5

您的最后一个if没有else- 这是 SML 中的语法错误。

于 2013-01-22T17:22:30.917 回答
2
fun is_older((y1 : int,m1 : int,d1 : int),(y2 : int, m2 : int, d2 : int))=
if y1 < y2 
then true 
else 
     if y1 = y2 andalso m1 < m2 
 then true 
 else 
      if y1 = y2 andalso m1 = m2 andalso d1 < d2
      then true 
      else false;
于 2013-01-30T13:41:26.257 回答