Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么类型';a和'';Z在SML中不匹配?_Sml - Fatal编程技术网

为什么类型';a和'';Z在SML中不匹配?

为什么类型';a和'';Z在SML中不匹配?,sml,Sml,我有以下递归函数: 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))

我有以下递归函数:

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;
fun测试仪(f:'a->'b,tl:(string*'a*'b)列表)=
案件tl
[] => []
|(t,c,e)::rest=>
设val tr=f(c)
在里面
如果tr(e)
然后((t),(e),tr):(测试器(f,rest))
else测试仪(f,其余)
结束;
加载时,我得到“错误:运算符和操作数不一致[UBOUND match]”:

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
lec1test.sml:17.5-19.26错误:运算符和操作数不一致[UBOUND match]
运算符域:“”Z*“”Z
操作数:“b*”Y
在表达上:
tr e
未捕获异常错误
在以下位置引发:../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
赋值给
f
函数的一个值,该值返回
'b
。然后我将结果与元组中的最后一个值进行比较,元组也是
'b
类型。有人能解释一下吗为什么这会给我一个错误?

不是所有类型都支持相等运算符
=
,只有所谓的相等类型。例如,
int
string list
bool*unit
都是相等类型,但函数类型
t->u
从来都不支持相等类型,因为没有合理的(可判定的)比较函数的方法

'a
这样的多态类型的值也不是相等类型,因为类型变量可以由任何类型实例化。要获得限制为相等类型的多态类型,您需要编写带有双勾号的类型变量,例如
''a

在您的情况下,将第一行更改为

fun tester (f : ''a -> ''b,  tl : (string * ''a * ''b) list) =
应该给你修一下