OCaml中如何在mli文件中引用ml文件中的模块?

4

这里有一个名为set.ml的文件,其中有一个名为IntSet的模块。我该如何在相应的接口文件set.mli中引用模块IntSet?

module IntSet = struct
  type t = int list;;
  let empty = [];;
  let rec is_member key = function
    | [] -> false
    | (x::xs) -> (
      if x = key then true
      else is_member key xs
    );;
end;;

let join xs ys = xs @ ys;;

这里是set.mli

val join : IntSet.t -> IntSet.t -> IntSet.t

如果我试图编译它,就会出现一个错误,声称模块IntSet未绑定。

% corebuild set.native
+ ocamlfind ocamlc -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -short-paths -thread -package core -ppx 'ppx-jane -as-ppx' -o set.cmi set.mli
File "set.mli", line 1, characters 11-19:
Error: Unbound module IntSet
Command exited with code 2.
Hint: Recursive traversal of subdirectories was not enabled for this build,
  as the working directory does not look like an ocamlbuild project (no
  '_tags' or 'myocamlbuild.ml' file). If you have modules in subdirectories,
  you should add the option "-r" or create an empty '_tags' file.

  To enable recursive traversal for some subdirectories only, you can use the
  following '_tags' file:

      true: -traverse
      <dir1> or <dir2>: traverse

Compilation unsuccessful after building 3 targets (1 cached) in 00:00:00.

我该如何公开在set.ml中定义的模块以便在定义中使用?

1个回答

2
我把set.mli更改为以下内容,编译器似乎很满意:
module IntSet : sig type t end
val join : IntSet.t -> IntSet.t -> IntSet.t

也许还需要更多的工作来使事情更易用。例如,无法创建类型为 IntSet.t 的值。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接