0
我想制作一个反转自定义列表的函数,但它不起作用,在前面的问题中,我已经提出了一个函数,但它使用了另一个函数,我希望不使用它任何外部功能,我已经写了一些代码,我希望有关如何使其工作的一些提示。mylist标准ml中的反向函数
datatype 'element mylist =
NIL
| CONS of 'element * 'element mylist;
fun reverse (CONS(x, NIL)) = CONS(NIL, x)
| reverse (CONS(x, xs)) = CONS((reverse xs), CONS(x, NIL));
我得到的错误是:
stdIn:89.5-90.60 Error: right-hand-side of clause doesn't agree with function result type [circularity]
expression: 'Z mylist mylist mylist
result type: 'Z mylist mylist
in declaration:
reverse =
(fn CONS (<pat>,<pat>) => CONS (<exp>,<exp>)
| CONS (<pat>,<pat>) => CONS (<exp>,<exp>))
什么是错的代码?