From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id RAA03103 for caml-redistribution; Tue, 9 Jan 1996 17:33:19 +0100 Received: from gr6.u-strasbg.fr (gr6.u-strasbg.fr [130.79.6.86]) by pauillac.inria.fr (8.6.10/8.6.6) with SMTP id JAA24002 for ; Tue, 9 Jan 1996 09:00:00 +0100 Received: by gr6.u-strasbg.fr (4.1/SMI-3.2-jjp/4/6/92) id AA08645; Tue, 9 Jan 96 09:04:10 +0100 Date: Tue, 9 Jan 96 09:04:10 +0100 From: boos@gr6.u-strasbg.fr (Christian Boos) Message-Id: <9601090804.AA08645@gr6.u-strasbg.fr> To: caml-list@pauillac.inria.fr Cc: arc@labri.u-bordeaux.fr Subject: Re: modules local to functions. In-Reply-To: <9601081207.AA14189@waves.labri.u-bordeaux.fr> References: <9601081207.AA14189@waves.labri.u-bordeaux.fr> Sender: weis > 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 (...) Hello, 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! One way to circumvent this problem is to change slightly the semantic of your argument module, for example: module type Specifyn = sig val n : unit -> int end ^^^^^^^ This should be not too inconvenient, and almost as simple to use as yours: module Makespecific(N:Specifyn) = struct type mytype = int let mirror () : mytype = N.n () ^^ end let toto_fred_n = ref 10 module Fred = Makespecific(struct let n () = !toto_fred_n end) let toto digits = toto_fred_n := digits; Fred.mirror () (This particular solution may even be expressed simpler: module type Specifyn = sig val n : int ref end ^^^ module Makespecific(N:Specifyn) = struct type mytype = int let mirror () : mytype = !N.n ^ end module Fred_N = struct let n = ref 10 end module Fred = Makespecific(Fred_N) let toto digits = Fred_N.n := digits; Fred.mirror () ) Hope it helps! Christian