我有以下递归函数:
fun tester (f:'a -> 'b, tl:(string * 'a * 'b) list) =
case tl of
[] => []
| (t, c, e)::rest =>
let val tr = f (c)
in
if tr <> (e)
then ((t), (e), tr)::(tester (f, rest))
else tester (f, rest)
end;
加载时出现“错误:运算符和操作数不同意 [UBOUND 匹配]”:
lec1test.sml:17.5-19.26 Error: operator and operand don't agree [UBOUND match]
operator domain: ''Z * ''Z
operand: 'b * 'Y
in expression:
tr <> e
uncaught exception Error
raised at: ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27
../compiler/TopLevel/interact/evalloop.sml:44.55
../compiler/TopLevel/interact/evalloop.sml:296.17-296.20
我发现我认为它与 tr 的通用绑定有关,但我不明白为什么这是个问题。我分配tr
给函数的值 from f
,它返回'b
。然后我将结果与元组中的最后一个值进行比较,该值也是 type 'b
。有人可以解释为什么这会给我一个错误吗?