2015-12-08 140 views
-1

我在接口OCaml中得到疯狂的类型

type t 
val empty : t 
val mem : int -> t -> bool 

现在我打电话

open ISet 
open OUnit2 
open Printf 
open List 
(* ... *) 
let s = mem 8 empty 

但我得到的是

This expression has type ISet.t but an expression was expected of type 
    int list 

声明下面的函数什么鬼正在进行?? 我甚至明确地定义了.ml文件中的类型

let mem (x : int) (set : t) = 
    let rec loop = function 
     | Node (l, k, r, _) -> 
      let c = cmp_val k x in 
      (contains k x) || loop (if c < 0 then l else r) 
     | Empty -> false in 
    loop set 

回答

2

你能提供更多的代码吗? t是一个抽象类型,所以我想你必须定义它。我怀疑这个mem不是正确的mem并指向List.mem。

+0

我完全同意,但它看起来像mem指向ISet.mem。 OCaml没有这个名字。这表明在OP的问题描述中有很多上下文缺失。 –

+0

事实上,我不知道存在'List.mem'这样的东西。感谢您指出。 – marmistrz

+0

当你想覆盖默认行为时,''open''语句非常有用。否则,我会建议你系统地使用虚线符号(''Iset.mem'')来避免这种混淆。 –