Ocaml:导出mli文件中的类型

FCo*_*FCo 7 ocaml

我有一个文件context.ml,其中定义了一个地图

module CtxMap = Map.make(struct type t = int let compare = compare end)
Run Code Online (Sandbox Code Playgroud)

和一个map_get类型的函数CtxMap.key -> 'a CtxMap.t -> 'a

如何将CtxMap声明添加到context.mli文件中?我无法找到办法,因为mli文件不能包含代码.

nlu*_*oni 8

module CtxMap : Map.S with type key = int
Run Code Online (Sandbox Code Playgroud)

map.mlocaml提供的文件中,仿函数的签名名称是S,并且key是您要向外部模块公开的唯一抽象类型.


Nik*_*chi 6

作为参考,您可以随时:

ocamlc -i -c context.ml
Run Code Online (Sandbox Code Playgroud)

将默认.mli文件输出到stdout.这个(在你的情况下)唯一的问题是它扩展了地图的签名.