Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Functors in separate files in OCaml?

Tags:

functor

ocaml

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" ... ?

like image 942
R u c k s a c k Avatar asked Apr 11 '12 16:04

R u c k s a c k


People also ask

What are Functors OCaml?

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.

What is a signature in OCaml?

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.


1 Answers

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.

like image 178
hcarty Avatar answered Sep 20 '22 13:09

hcarty