【问题标题】:What does 'int ?. tree' mean in an SML error message?'int 是什么意思?树'在 SML 错误消息中是什么意思?
【发布时间】:2012-10-01 14:18:56
【问题描述】:

我为一个类编写了以下 SML 代码:

fun lookup (cmp: 'a * 'a -> order) (x: 'a, t: 'a tree) : 'a option =
    case t of
      Empty => NONE
    | Node(l,y,r) =>
      case cmp(x,y) of
        EQUAL => SOME y
      | LESS => lookup (cmp) (x,r)
      | GREATER => lookup (cmp) (x,l)

在测试中:

val SOME 3 = lookup Int.compare (3, Node(Empty,3,Empty));

然后返回以下错误:

stdIn:153.1-166.12 Error: operator and operand don't agree [tycon mismatch]
  operator domain: int * int ?.tree
  operand:         int * int tree
  in expression:
    (lookup Int.compare) (3,Node (Empty,3,Empty))

?. 是什么意思?

【问题讨论】:

    标签: syntax-error currying smlnj


    【解决方案1】:

    这通常与跨模块的可见性受限有关。你的“树”定义是什么样的?您可能需要告诉编译器您在一个模块中的“树”类型与另一个模块中的相同。

    【讨论】:

    • 我和我的教授谈过,他也提到这是由于改变了一个类型的定义。谢谢!
    猜你喜欢
    • 2015-08-28
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 2017-06-11
    • 2018-03-05
    相关资源
    最近更新 更多