Ocaml:导出mli文件中的类型
我有一个文件context.ml,其中定义了映射Ocaml:导出mli文件中的类型,ocaml,Ocaml,我有一个文件context.ml,其中定义了映射 module CtxMap = Map.make(struct type t = int let compare = compare end) 还有一个函数map\u get,类型为CtxMap.key->'a CtxMap.t->'a 如何将CtxMap声明添加到context.mli文件中? 由于mli文件不能包含代码,所以我找不到一种方法来实现它 module CtxMap : Map.S with type key = int 在oc
module CtxMap = Map.make(struct type t = int let compare = compare end)
还有一个函数map\u get
,类型为CtxMap.key->'a CtxMap.t->'a
如何将CtxMap声明添加到context.mli文件中?
由于mli文件不能包含代码,所以我找不到一种方法来实现它
module CtxMap : Map.S with type key = int
在ocaml提供的
map.ml
文件中,函子的签名名称为S
,并且键是您希望向外部模块公开的唯一抽象类型。作为参考,您可以始终执行以下操作:
ocamlc -i -c context.ml
将默认的.mli
文件输出到标准输出。唯一的问题是(在您的情况下)它会扩展映射的签名。您需要添加-c
以避免添加所有依赖项--此选项会编译,但不会链接。