OCaml对类型非常着迷

OCaml对类型非常着迷,ocaml,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 到底发生了

我在接口中声明了以下函数

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
let mem(x:int)(set:t)=
让rec循环=函数
|节点(l、k、r)->
设c=cmp_val k x in
(包含kx)| |循环(如果c<0,则l否则r)
|空->错误输入
环集

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

我完全同意,但看起来mem指向的是ISet.mem。OCaml中没有这个名字。这表明OP对这个问题的描述中缺少了很多上下文。事实上,我不知道存在像
List.mem
这样的东西。感谢您指出这一点。
open
语句在您想要覆盖默认行为时非常有用。否则,我建议您系统地使用点符号(
Iset.mem
)来避免这种混淆。