是否有可能在没有创建“必须实现的新模块”的情况下在mli中模块化。 这个例子很有意思,但是,假设我有以下源文件int_wrapper.ml。OCaml:如何获得模块别名本地mli文件
type t = Int64.t
let zero = Int64.of_string "0"
我想为它定义一个接口文件,但Int64.t很长,所以我想缩写它。
module I = Int64
val zero : int -> I.t
当试图编译模块,我(不出所料)收到以下错误
ocamlbuild int_wrapper.cmo
+ ~/.opam/4.03.0/bin/ocamlc.opt -c -o int_wrapper.cmo int_wrapper.ml
File "int_wrapper.ml", line 1:
Error: The implementation int_wrapper.ml
does not match the interface int_wrapper.cmi:
The module `I' is required but not provided
Command exited with code 2.
Compilation unsuccessful after building 4 targets (0 cached) in 00:00:00.
Exit 10
那是因为module I = Int64
不是别名。实际上,我定义了一个新模块 - 仅仅发生 - 与Int64
相同,并且由于该模块在签名中,因此我需要在源文件中提供一个实现。 有没有办法在接口文件中获得真正的别名?