每月练习次数(SML错误未绑定变量)

每月练习次数(SML错误未绑定变量),sml,Sml,我正在尝试学习SML,我正在尝试实现两个功能。第一个函数工作正常,但当我添加第二个函数时,它会给我一个运行时错误: stdIn:1.2-1.17 Error: unbound variable or constructor: number_in_month 这是在调用函数编号时发生的。我的代码是: fun is_older(d1 :int*int*int,d2 :int*int*int) = (#1 d1) < (#1 d2) andalso (#2 d1) < (#2 d2

我正在尝试学习SML,我正在尝试实现两个功能。第一个函数工作正常,但当我添加第二个函数时,它会给我一个运行时错误:

stdIn:1.2-1.17 Error: unbound variable or constructor: number_in_month
这是在调用函数编号时发生的。我的代码是:

 fun is_older(d1 :int*int*int,d2 :int*int*int) =
  (#1 d1) < (#1 d2) andalso (#2 d1) < (#2 d2) andalso (#3 d1) < (#3 d2)


fun number_in_month(da :(int * int * int) list ,mo : int) =
    if da = []
    then 0
    else if (#2(hd da)) = mo
     then 1 + number_in_month((tl da),mo)
    else 0 + number_in_month((tl da),mo)
fun更老(d1:int*int*int,d2:int*int*int)=
(#1 d1)<(#1 d2)及〈2 d1)<(#2 d2)及〈3 d1)<(#3 d2)
月内有趣数字(da:(int*int*int)列表,mo:int)=
如果da=[]
然后0
如果(#2(hd da))=mo
然后1+每月的数字((tl da),mo)
其他0+每月的数量((tl da),mo)

你的问题听起来与以下问题惊人地相似:(8个月前),(9个月前)和(8个月前),因此你提出创造性问题肯定得不到分数

上面的一些问题已经得到了广泛的回答。看看他们

以下是以更好的风格重写的代码:

(* Find better variable names than x, y and z. *)
fun is_older ((x1,y1,z1), (x2,y2,z2)) =
    x1 < x2 andalso y1 < y2 andalso z1 < z2

fun number_in_month ([], mo) = 0
  | number_in_month ((x,y,z)::rest, mo) =
    if y = mo then 1 + number_in_month(rest, mo)
              else 0 + number_in_month(rest, mo)
(*查找比x、y和z*更好的变量名)
乐趣更大((x1,y1,z1),(x2,y2,z2))=
x1
您确定该错误会指向该代码吗?此外,在SML中,未绑定变量肯定没有运行时错误。代码运行良好。该错误意味着未定义该函数。也许你只是忘了重新加载文件。或者更好的是:
(如果y=mo,那么1 else 0)+number_in_month(rest,mo)
:)或者更好的是:
fun number_in_month(dates,mo)=foldl(fn(((,mo'),n)=>(如果mo=mo',n else 0)+n)0个日期