我有一个文件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文件不能包含代码.
module CtxMap : Map.S with type key = int
Run Code Online (Sandbox Code Playgroud)
在map.ml
ocaml提供的文件中,仿函数的签名名称是S
,并且key
是您要向外部模块公开的唯一抽象类型.
作为参考,您可以随时:
ocamlc -i -c context.ml
Run Code Online (Sandbox Code Playgroud)
将默认.mli
文件输出到stdout.这个(在你的情况下)唯一的问题是它扩展了地图的签名.