Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ocaml: Exporting a type in an mli file

Tags:

ocaml

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.

like image 889
FCo Avatar asked Feb 02 '11 21:02

FCo


2 Answers

module CtxMap : Map.S with type key = int

In the map.ml file provided with ocaml, the name of the signature for the functor is S, and key is the only abstract type you want to expose to the outside modules.

like image 130
nlucaroni Avatar answered Nov 17 '22 15:11

nlucaroni


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.

like image 43
Niki Yoshiuchi Avatar answered Nov 17 '22 17:11

Niki Yoshiuchi