Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referring to module types defined in toplevel files

Tags:

ocaml

In OCaml, if your project has a file called code.ml you can refer to it in other files using the module name Code. I was wondering if you defined an .mli file if you could refer to the signature it defines in a similar way. For example if you had a file called wow.mli and you could have another file with the declaration

module Func(St : Wow) = struct ... end

Is there a way to do something along those lines?

like image 509
dalastboss Avatar asked Dec 05 '25 10:12

dalastboss


1 Answers

This works for me:

module Func(St: module type of Wow) = struct ... end

In detail here's what I did:

$ cat wow.mli
val f : int -> int
$ cat m.ml
module Func (St: module type of Wow) = struct let f x = St.f x end
$ ocamlopt -c wow.mli
$ ocamlopt -c m.ml
like image 86
Jeffrey Scofield Avatar answered Dec 07 '25 16:12

Jeffrey Scofield