【发布时间】:2023-03-15 06:31:01
【问题描述】:
fun insert R x [] acc = [x]
| insert R x (h::t) acc =
if R (x,h) then acc::(x::(h::t))
else(
acc=acc::h;
insert R x t acc
);
fun isort_aux R [] acc = acc
| isort_aux R (x::xs) acc =
isort_aux xs (insert R x acc [])
fun isort_2 R xs = isort_aux R xs []
我正在尝试在 sml 中编写用于插入排序的尾递归代码,为此我创建了一个累加器“acc”,但在第 5 行 acc=acc::h 出现以下错误
Standard ML of New Jersey v110.78 [built: Thu Aug 31 03:45:42 2017]
- stdIn:5.3-5.13 Error: operator and operand don't agree [circularity]
operator domain: 'Z * 'Z list
operand: 'Z * 'Z
in expression:
acc :: h
-
【问题讨论】:
-
acc = acc::h是一个比较,你不能将h和acc放在一起。您可能应该复习 SML 的基础知识,并从明确写下类型开始。
标签: error-handling compiler-errors smlnj