From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 72FADBB81 for ; Wed, 8 Dec 2004 17:10:57 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iB8GAvXE032645 for ; Wed, 8 Dec 2004 17:10:57 +0100 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 RAA15663 for ; Wed, 8 Dec 2004 17:10:56 +0100 (MET) Received: from yquem.inria.fr (yquem.inria.fr [128.93.8.37]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iB8GAu5K032642 for ; Wed, 8 Dec 2004 17:10:56 +0100 Received: by yquem.inria.fr (Postfix, from userid 18180) id 7FCB1BB81; Wed, 8 Dec 2004 17:10:56 +0100 (CET) Date: Wed, 8 Dec 2004 17:10:56 +0100 From: Xavier Leroy To: caml-list@inria.fr Subject: Re: [Caml-list] Type constraints Message-ID: <20041208161056.GA703@yquem.inria.fr> References: <20041206195527.GA32094@draco.skynet> <41B557D4.2000306@inria.fr> <076FEF06-4856-11D9-8195-000D9345235C@inria.fr> <41B5C4C8.9040701@ps.uni-sb.de> <41B5F1B2.3000503@inria.fr> <9296F5C2-4893-11D9-8195-000D9345235C@inria.fr> <41B62407.4020102@inria.fr> <74A16EF6-4907-11D9-8195-000D9345235C@inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <74A16EF6-4907-11D9-8195-000D9345235C@inria.fr> User-Agent: Mutt/1.3.28i X-Miltered: at nez-perce with ID 41B72791.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41B72790.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 hmmm:01 expansive:01 expansive:01 struct:01 struct:01 forall:01 nonexpansive:01 nonexpansive:01 polymorphism:01 subtyping:01 ...:98 ...:98 polymorphic:01 expression:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: > Hmmm... Now I don't know whether it's safe or not, and I don't know > whether someone checked its safety before excluding it from the value > restriction code... You word it in a slightly backward way: it is always safe to claim that an expression is expansive and its type should not be generalized; it's the converse (asserting that an expression is non-expansive) that is potentially dangerous and requires some semantic evidence that it is safe. The current treatment of "let module" as being always expansive just errs on the safe side, in the absence of this semantic evidence. > >So I don't understand why the same cannot apply to local modules. If > >the let-module-in were declared "safe" for the value restriction, > >shouldn't > > > >let module M = struct let v = ref [] end in M.v > > > >yield a non-generalized type for the same reason as for the non-local > >case (and not because of the value restriction) ? I don't follow you here. So, OK, your expression E above (E = let module M = struct let v = ref [] end in M.v) has type alpha list ref for a fresh variable alpha. If we were to classify E as non-expansive, we could do let x = E in E' and in E', x would have polymorphic type forall alpha, alpha list ref, from which it is easy to break type safety. So, your example shows that it would be unsafe to say that a "let module M = A in B" expression is nonexpansive if B is nonexpansive. One would need to inspect the module expression A to establish that it is nonexpansive. This is what we do for ordinary "let" expressions: "let x = A in B" is nonexpansive if both A and B are nonexpansive. There are two concerns here. The practical one is that the module language is quite complex and I really don't feel like implementing a syntactic nonexpansiveness check for module expressions. The conceptual concern is that the type system for the module language is somewhat richer than that of the core language -- it has "deep" polymorphism, subtyping and some forms of dependent types -- so it is not entirely clear to me that the value restriction and the syntactic nonexpansiveness criterion that work for the core language would also work for the module language. - Xavier Leroy