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 E8129BB81 for ; Wed, 8 Dec 2004 01:27:42 +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 iB80Rg95025394 for ; Wed, 8 Dec 2004 01:27:42 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA17397 for ; Wed, 8 Dec 2004 01:27:41 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iB80Rd5H017856 for ; Wed, 8 Dec 2004 01:27:40 +0100 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id iB80Rc4k002630; Wed, 8 Dec 2004 09:27:38 +0900 (JST) Date: Wed, 08 Dec 2004 09:27:24 +0900 (JST) Message-Id: <20041208.092724.63079073.garrigue@math.nagoya-u.ac.jp> To: wlovas@stwing.upenn.edu Cc: caml-list@inria.fr Subject: Re: [Caml-list] Type constraints From: Jacques Garrigue In-Reply-To: <20041207181344.GA14891@force.stwing.upenn.edu> References: <41B5C4C8.9040701@ps.uni-sb.de> <20041207181344.GA14891@force.stwing.upenn.edu> X-Mailer: Mew version 4.0.64 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41B64A7E.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41B64A7B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 lovas:01 wlovas:01 stwing:01 upenn:01 damien:01 wrote:01 rossberg:01 wrote:01 struct:01 struct:01 typechecker:01 nonexpansive:01 typecore:01 texp: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: From: William Lovas > On Tue, Dec 07, 2004 at 06:44:36PM +0100, Damien Doligez wrote: > > > > On 7 Dec 2004, at 15:57, Andreas Rossberg wrote: > > > > >Is this really a counter-example? I don't see any problem with making > > >it polymorphic - it evaluates to ref, and ref can happily be > > >polymorphic. > > > > Yes, well I simplified it a bit too much. Try this instead: > > > > let module M = struct let v = ref [] end in M.v;; > > I'm still not convinced. Yes, the type variable should not be generalized > in the above, by analogy with: > > # ref [];; > - : '_a list ref = {contents = []} > > But the `let module' in question -- or one similar in spirit, at least -- > > # let module M = struct let v = fun x -> x end in M.v;; > - : '_a -> '_a = > > is analogous to the expression > > # fun x -> x > - : 'a -> 'a = > > in which the type variable *is* generalized. Analogies don't help you here, because the typechecker doesn't work by analogies, but by explicit rules. If you're curious, there is a function is_nonexpansive in typing/typecore.ml. Only expressions for which this function returns true will be generalized. (This is a direct implementation of the syntactic value-generalization scheme.) Now, this function doesn't now about Texp_letmodule, so any use of this construct will never be generalized. I don't know exactly why this was omitted, but I see the combination of two possible reasons: this requires some amount of extra code, and one must assess its validity. Yet I suppose this could be done. By the way, the code is already there for immediate objects, so the alternative approach with polymorphic methods does work (but generates more code). # let o = object method v : 'a. 'a -> 'a = fun x -> x end in fun x -> o#v x;; - : 'a -> 'a = Jacques Garrigue