I want to have a big functor Hello(Blah: Blah_type) and save it in the file hello.ml, but how do I do this?
If I was just in my top level file, I'd have module Hello(Blah: Blah_type) = struct val x = 2 end
but how do I put the argument in hello.ml? I can't just have the whole file being "val x = 2" ... ?
A functor is a module that is parametrized by another module, just like a function is a value which is parametrized by other values, the arguments. It allows one to parametrize a type by a value, which is not possible directly in OCaml without functors.
A signature specifies which components of a structure are accessible from the outside, and with which type. It can be used to hide some components of a structure (e.g. local function definitions) or export some components with a restricted type.
OCamlPro has a compiler patch and external tool which may support this:
http://www.ocamlpro.com/blog/2011/08/10/ocaml-pack-functors.html
As far as I know the official compiler release does not support .ml files as functors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With