From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA25868 for caml-red; Mon, 8 Jan 2001 18:58:38 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA17576 for ; Mon, 8 Jan 2001 16:18:04 +0100 (MET) Received: from mail5.microsoft.com (mail5.microsoft.com [131.107.3.121]) by nez-perce.inria.fr (8.11.1/8.10.0) with SMTP id f08FI3r27712 for ; Mon, 8 Jan 2001 16:18:03 +0100 (MET) Received: from 157.54.9.108 by mail5.microsoft.com (InterScan E-Mail VirusWall NT); Mon, 08 Jan 2001 07:11:33 -0800 (Pacific Standard Time) Received: by inet-imc-05.redmond.corp.microsoft.com with Internet Mail Service (5.5.2651.58) id ; Mon, 8 Jan 2001 07:11:31 -0800 Message-ID: <112C6E8A1B25D34BB27D48D2FD2E96CFC9429A@TVP-MSG-02.europe.corp.microsoft.com> From: Claudio Russo To: caml-list@inria.fr Cc: frisch@clipper.ens.fr Subject: RE: first class modules (was: alternative module systems) Date: Mon, 8 Jan 2001 07:11:12 -0800 X-Mailer: Internet Mail Service (5.5.2651.58) content-class: urn:content-classes:message Sender: weis@pauillac.inria.fr (This was a response to Xavier and Mosml hackers, but I've been asked to forward it to the list). > Hi Claudio, > > > BTW, in Moscow ML, the "open" construct is integrated more naturally > > as a special form of declaration, plus a side condition that > > disallows an open declaration from appearing within the body of a > > functor (for soundness reasons). This lets you open first-class > > modules at top-level and within substructures, which can be more > > convenient. > > That sounds interesting. I was thinking exactly along these lines. > Do you have this written down somewhere? > > Xavier In Moscow there is no separate open expression, just a new form of structure binding that let's you deconstruct a first-class module (there is a similar form for functors): := ... | as = This lets you write declarations like structure Bar as S = if .. then .. else ...; wherever an ordinary declaration can occur. This is actually more general (and convenient) than the open construct because it lets you open first-class modules at top-level and within structure bodies, not just within Core expressions. If functors are always generative, this is ok, but it interacts badly with applicative functors (programs can go "wrong"). To avoid this, in Moscow we simply place a syntatic restriction on functor bodies: "the body of any functor (whether applicative or generative) cannot contain a structure level declaration of the above form, *unless* that declaration occurs within a dec in a Core "let in end" expression" In the examples below, the structure Ok is legal, the functor Wrong is illegal but the functor Ok is legal. signature S = sig type t val f:t end; structure A = struct type t = int -> int val f x = x+1 end; structure B = struct type t = bool val f = true end; structure Ok as S = if ... then [structure A as S] else [structure B as S] (* legal *) functor Wrong(val b:bool) = struct structure C as S =if b then [structure A as S] else [structure B as S] end (* ilegal, because of "open" within immediate structure binding *) functor Ok(val b:bool) = struct val c = let structure C as S = if b then [structure A as S] else [structure B as S] in ... end end (* legal again, because "open" is within Core let. *) I've got a formal revision of the SML definition, if anyone is interested, just ask. The Mosml doc also describes the syntax in more detail (if I recall correctly). Of course, it's probably possible to come up with a more permissive restriction, but I like this one because its simple. Cheers, Claudio