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 SAA04427 for caml-redistribution; Tue, 9 Jan 1996 18:58:09 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id KAA25371 for ; Tue, 9 Jan 1996 10:35:26 +0100 Received: from victor.labri.u-bordeaux.fr (root@victor.labri.u-bordeaux.fr [147.210.8.168]) by concorde.inria.fr (8.7.1/8.7.1) with SMTP id KAA20023 for ; Tue, 9 Jan 1996 10:35:25 +0100 (MET) Received: from waves.labri.u-bordeaux.fr by victor.labri.u-bordeaux.fr (4.1/SM-mailhost-BORDEAUX-1.0) id AA09938; Tue, 9 Jan 96 10:36:01 +0100 Received: from [127.0.0.1] by waves.labri.u-bordeaux.fr (4.1/SM-BORDEAUX0.1) id AA21977; Tue, 9 Jan 96 10:34:00 +0100 Message-Id: <9601090934.AA21977@waves.labri.u-bordeaux.fr> From: Andrew Conway Reply-To: arc@labri.u-bordeaux.fr To: caml-list@pauillac.inria.fr Cc: boos@gr6.u-strasbg.fr (Christian Boos) Subject: Re: modules local to functions. In-Reply-To: Your message of "Tue, 09 Jan 1996 09:04:10 +0100." <9601090804.AA08645@gr6.u-strasbg.fr> Date: Tue, 09 Jan 1996 10:34:00 +0100 Sender: weis I wrote: > > 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 (...) Christian Boos commented: >I have encountered a similar problem yesterday! >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! Ah. I expected (though I hadn't looked into the code at all) that a run time structure creation (eg struct let n = variable end) was very similar to the creation of a tuple/normal structure, just requiring sticking some values into a block of memory. I then expected that a module creation from a functor was very similar to a partial function application, (with perhaps a bit of execution) and could thus be done at run time (as distinct from, say C++ templates which produce specialised code for each application). But it may well be significantly more complex than that. > One can get around the problem by defining n as a function or reference > and changing it dynamically. Ugh! I hadn't thought of that, and it is a good idea even if just a little inelegant. Unfortunately it is not appropriate in my case as I have several values in the structure which get defined when the module is created and which depend on n...ie: module Makespecific(N:Specifyn) = struct type mytype = int let computednumber = complexfunction N.n let mirror () : mytype = computednumber end and I only want to call complexfunction once for each module instantiation. Of course, I could make "computednumber" a reference, and I could have a function "change_n_and_recompute_everything", but again it is an inelegant solution that is hard to understand, and I end up with "!"s all over the code for no algorithmically justifyable reason. Yeah yeah, I know I am being picky... Thanks, Andrew.