From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id RAA24158 for caml-redistribution; Wed, 10 Jan 1996 17:01:20 +0100 Received: (from xleroy@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id QAA22663; Wed, 10 Jan 1996 16:27:22 +0100 From: Xavier Leroy Message-Id: <199601101527.QAA22663@pauillac.inria.fr> Subject: Re: modules local to functions. To: arc@labri.u-bordeaux.fr Date: Wed, 10 Jan 1996 16:27:22 +0100 (MET) Cc: caml-list@pauillac.inria.fr In-Reply-To: <9601081207.AA14189@waves.labri.u-bordeaux.fr> from "Andrew Conway" at Jan 8, 96 01:07:25 pm MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis Andrew Conway wrote: > However, there are cases when I want to define a module in the middle > of a 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 ();; Christian Boos replied: > My understanding is that YOU CAN'T do that in CSL at all: functor > application means code generation, and there's no runtime code > generation! This is wrong. Functors are compiled once and for all, and functor application proceeds exactly as function application. Ada generics and C++ templates are generally implemented by recompilation as Christian described, but that's just because these languages don't implement lexical closures in their full generality. So, there is no deep reason why modules could not be defined locally to a (core-language) expression. Standard ML allows this (the "let structure" and "local" constructs). That was left out of Caml Special Light for simplicity. In particular, not having module expressions inside core-language expressions avoids mutual recursion between the module language and the core language; this makes both the theory and the implementation simpler. I still need to be convinced of the usefulness of local functor applications (Andrew Conway's example was too sketchy to illuminate me), but it can definitely be done. - Xavier Leroy