![](/img/trans.png)
[英]OCaml share structure between mli file and signature inside ml file
[英]How to load .ml file with its corresponding .mli file in utop?
简单地说,假设我有一个名为moduleExample.ml
的实现文件和一个位于同一目录中的名为moduleExample.mli
的接口文件。
我怎样才能将它们一起加载,以使接口moduleExample.mli
中未列出的功能从moduleExample.ml
在utop
的签名中隐藏? 此外,如何通过moduleExample.mli
文件进行类型抽象?
我认为这样做的正确方法,或者更一般地在顶层加载多个模块和接口的整个项目,是使用构建系统来编译所有模块并将它们链接到顶层。
使用 沙丘,您可以按照此处所述执行dune utop directory
。 为了详尽无遗,这里有一个架构示例:
沙丘.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.
然后在模块Ex
上使用#show
指令,给出:
utop # #show Ex;;
module Ex : sig type t val of_int : int -> t val print : t -> unit end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.