ocamlfunctor

Functors in separate files in 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 ... ?


Solution

  • It is not possible. Source files are always represented as ordinary modules, not functors. This is trivially solved with one extra open.