modules local to functions.

Andrew Conway (arc@labri.u-bordeaux.fr)
Mon, 08 Jan 1996 13:07:25 +0100

Message-Id: <9601081207.AA14189@waves.labri.u-bordeaux.fr>
From: Andrew Conway <arc@labri.u-bordeaux.fr>
To: caml-list@pauillac.inria.fr
Subject: modules local to functions.
Date: Mon, 08 Jan 1996 13:07:25 +0100

Resume en tres pauvre Francais: je voudrais utiliser un "functor" au milleau
d'une fonctionne, en utilisant les parametres de la fonctionne dans le "sig".
Je ne peut pas le faire. Pourquoi pas?

---------------------------------

I have a functor such as follows:

module type Specifyn = sig val n : int end;;

module Makespecific(N:Specifyn) = struct
type mytype = int
let mirror () : mytype = N.n
end;;

I can apply it at the main level like:

module Fred = Makespecific(struct let n = 7 end);;

However, there are cases when I want to define a module in the middle
of a function (eg a functor of packed binary arrays where I want to
determine the number of bits used at run time depending upon the
arguement of the function). That is, I would like to be abe to do:

let toto digits =
module Fred = Makespecific(struct let n = digits end) in
Fred.mirror ();;

which seems to be reasonably within the spirit and syntax of csl.
Even if that is not possible, something else like:

let toto digits =
let u = Makespecific(struct let n = digits end).mirror () in
u
;;

would also be useful although not an entirely satisfactory solution.

Is this plausible? I seem to remember a discussion something along this
line a while ago, but it may have been for sml.

Thanks for making csl available,

Andrew.