Re: modules local to functions.

Xavier Leroy (xleroy@pauillac.inria.fr)
Wed, 10 Jan 1996 16:27:22 +0100 (MET)

From: Xavier Leroy <xleroy@pauillac.inria.fr>
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)
In-Reply-To: <9601081207.AA14189@waves.labri.u-bordeaux.fr> from "Andrew Conway" at Jan 8, 96 01:07:25 pm

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