English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: modules local to functions.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1996-01-10 (16:01)
From: Xavier Leroy <xleroy@p...>
Subject: Re: modules local to functions.

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