Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] module/signature pattern concerns
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: mattwb <mattwb@a...>
Subject: [Caml-list] module/signature pattern concerns

A common pattern that has developed in much of my production
O'Caml code is to write interface files that look something like this:

foo.mli

        module type PARAMS =
            sig
                (* define fixed, run-time configuration parameters *)
            end

        module type ELT =
            sig
                (* ... *)
            end

        module Make (P : PARAMS) : ELT

I define a set of parameters in the PARAMS signature which configure
the Make functor.  So the user program would be something like this:

    let module F = Foo.Make(
        struct
            (* ... *)
        end)
    in
    F.main()

This has become a convenient pattern, and allows me to write more
'opaque' signatures because I don't have to include any parameters in the
ELT signature.  I can use the resulting ELT module as a parameter
in other PARAM signatures in other modules.  This leads to a nice layering
effect.

My concern is that I will take a significant performance hit by using
functors
so much and using so many layers.  I haven't noticed this problem in any of
the code that I have written, but I am slightly paranoid that, at a much
larger
scale, this would become an issue.

As an alternative, I could write something similar without using functors
and
expose some of the module configuration:

foo.mli

        module type ELT
            sig
                (* ... *)
            end
        (* List run-time configuration parameters here *)
        (* This section matches the ELT signature *)

I realize I that I can check this easily myself, but I thought I'd ask the
list so
I could get some possibly new ideas.

Any suggestions?
Alternatives?




-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners