error-handling - SMLcircularity操作数和运算符的错误不一致

标签 error-handling compiler-errors smlnj

    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; insert R x t acc



在SML中,在此处进行两次 call 不起作用。由于语言的结构方式,您只能在SML中做一件事。几周前开始使用SML时,我是这样做的,但对我来说却不起作用。

正如@moldbnilo的评论所说,您的代码正在尝试将acc与acc::h进行比较,而不是将其设置为等于acc。

我对SML还是很陌生,因此请适量服用,因为可能不正确。

关于error-handling - SMLcircularity操作数和运算符的错误不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59936633/

相关文章:

facebook-graph-api - facebook publish_action-检查是否按下跳过

sml - 将字符串列表的每个元素作为字符串输出在其自己的行上 - sml

sml - SML 中的类型转换

excel - 如何处理 VBA 中的 DLL 错误?

python - 方法未定义 - 编译器如何错过它?

ios - 提醒创建失败,错误消息为 NIL

c++ - 无法在派生模板类中访问模板基类的成员

c++ - 如何在 Vector 类中创建 operator=?

c++ - 使用 STL 算法的命名空间和用户定义的运算符

floating-point - 为什么我不能在 Standard ML 中比较实数?