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>))
什麼是錯的代碼?