-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
我完全同意,但它看起来像mem指向ISet.mem。 OCaml没有这个名字。这表明在OP的问题描述中有很多上下文缺失。 –
事实上,我不知道存在'List.mem'这样的东西。感谢您指出。 – marmistrz
当你想覆盖默认行为时,''open''语句非常有用。否则,我会建议你系统地使用虚线符号(''Iset.mem'')来避免这种混淆。 –