On Sun, Nov 20, 2011 at 6:17 PM, OGrandeDiEnne <[email protected]> wrote:
> This solution is elegant but has a big limit: the edit function must
> be completely defined at compile time, since I can not define an
> EditModule at runtime (i suppose).

Not true!  You can define local modules at runtime using "let module" [1]:

let main user_edit_function =
    let module Editor = struct
        let edit = user_edit_function
    end in
    let module Foo = FunctionSet(Editor) in
    Foo.f1...

What you can't do with this syntax is use Foo outside of the scope
introduced by let module (i.e. you can't pass it to a function).  If
you need to do this, you need at least OCaml 3.12, in which you can
use first-class module syntax [2]:

let main user_edit_function =
    let module Editor = struct
        let edit = user_edit_function
    end in
    let module Foo = FunctionSet(Editor) in
    main_aux (module Foo: FunctionSetSig)

let main_aux function_set =
    let module Bar = (val function_set: FunctionSetSig) in
    Bar.f1 ...

(where FunctionSetSig is the signature of the result module type of
your functor FunctionSet)

- Chris

[1] http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc74
[2] http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc81

-- 
You received this message because you are subscribed to the Google Groups 
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html

Reply via email to