module - 如何在 utop 中加载 .ml 文件及其对应的 .mli 文件?

标签 module interface ocaml ocamlbuild utop

简单地说,假设我有一个名为 moduleExample.ml 的实现文件。和同一目录中的接口(interface)文件 moduleExample.mli .
我怎样才能将它们加载在一起,以使界面中未列出的功能moduleExample.mlimoduleExample.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/

相关文章:

VB.NET、类和模块与函数

java - 实现接口(interface)

C++调用接口(interface)方法导致指针在VS2012中不完整

oop - 实现接口(interface)的缺点

module - 在 OCaml 中从 Map 扩展模块

Ocaml utop 库路径,核心模块

ocaml - 在 ocaml 中编写多行函数

Haskell递归/循环模块定义?

module - 如何编写 use 语句以导入名称但将其用作 mod1::mod2::item?

module - 覆盖 Magento 自定义模块中的核心 Controller