【发布时间】:2012-10-04 21:31:45
【问题描述】:
我想创建一个反转自定义列表的函数,但它不起作用,我在上一个问题中被建议使用一个函数,但它使用了另一个函数,我想在没有任何外部函数的情况下使用它,我'我已经写了一些代码,我会很感激一些关于如何使它工作的提示。
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>))
代码有什么问题?
【问题讨论】: