gpt4 book ai didi

OCaml 引用 mli 内的 ml 文件中的模块

转载 作者:行者123 更新时间:2023-12-02 01:22:45 27 4
gpt4 key购买 nike

这里我有一个文件set.ml带有一个名为 IntSet 的模块.如何引用模块IntSet里面对应的接口(interface)文件set.mli ?

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是未绑定(bind)的。
% 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 中定义的模块所以我可以在定义中使用它?

最佳答案

我将 set.mli 更改为此,编译器似乎很高兴:

module IntSet : sig type t end
val join : IntSet.t -> IntSet.t -> IntSet.t

可能还有更多工作可以使东西可用。无法生成 IntSet.t 类型的值, 例如。

关于OCaml 引用 mli 内的 ml 文件中的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38947664/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com