简单地说,假设我有一个名为 moduleExample.ml
的实现文件。和同一目录中的接口(interface)文件 moduleExample.mli
.
我怎样才能将它们加载在一起,以使界面中未列出的功能moduleExample.mli
对 moduleExample.ml
隐藏在 utop
中的签名?此外,如何通过 moduleExample.mli
进行类型抽象?文件?
最佳答案
我认为这样做的正确方法,或者更一般地在顶层加载多个模块和接口(interface)的整个项目,是使用构建系统来编译所有模块并将它们链接到顶层。
使用 dune , 你可以这样做 dune utop directory
如所述here .为了详尽无遗,这里有一个架构示例:
沙丘.ml
(library
(name dummy)
(wrapped false)
)
例 type t = int
let of_int x = x
let to_string = string_of_int
let add = (+)
let print x = print_string (to_string x)
例如.mli type t
val of_int : int -> t
val print : t -> unit
通过执行 dune utop .
将所有内容加载到 utop然后使用 #show
模块指令 Ex
,给出:utop # #show Ex;;
module Ex : sig type t val of_int : int -> t val print : t -> unit end
关于module - 如何在 utop 中加载 .ml 文件及其对应的 .mli 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65304960/