简体   繁体   中英

Ocaml: Exporting a type in an mli file

I have a file context.ml where a map is defined

module CtxMap = Map.make(struct type t = int let compare = compare end)

and a function map_get with type CtxMap.key -> 'a CtxMap.t -> 'a

How do I add the CtxMap declaration to the context.mli file? I can't find a way to do it as mli files can't contain code.

module CtxMap : Map.S with type key = int

在ocaml提供的map.ml文件中, map.ml函数的签名名称为Skey是您要向外部模块公开的唯一抽象类型。

For reference, you can always do:

ocamlc -i -c context.ml

to output the default .mli file to stdout. The only issue with this (in your case) is that it expands the signature of the map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM