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 D0001BB81 for ; Tue, 7 Dec 2004 19:13:49 +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 iB7IDn4V018565 for ; Tue, 7 Dec 2004 19:13:49 +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 TAA06212 for ; Tue, 7 Dec 2004 19:13:49 +0100 (MET) Received: from nexus.stwing.upenn.edu (NEXUS.STWING.UPENN.EDU [165.123.132.61]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iB7IDl9A006715 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Tue, 7 Dec 2004 19:13:48 +0100 Received: from force.stwing.upenn.edu (force.stwing.upenn.edu [165.123.132.65]) by nexus.stwing.upenn.edu (8.12.10/8.12.9) with ESMTP id iB7IDkHA012335 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Tue, 7 Dec 2004 13:13:46 -0500 (EST) Received: from force.stwing.upenn.edu (localhost [127.0.0.1]) by force.stwing.upenn.edu (8.12.10/8.12.9) with ESMTP id iB7IDjh4015685 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 7 Dec 2004 13:13:45 -0500 (EST) Received: (from wlovas@localhost) by force.stwing.upenn.edu (8.12.10/8.12.9/Submit) id iB7IDjBa015658 for caml-list@inria.fr; Tue, 7 Dec 2004 13:13:45 -0500 (EST) Date: Tue, 7 Dec 2004 13:13:44 -0500 From: William Lovas To: caml users Subject: Re: [Caml-list] Type constraints Message-ID: <20041207181344.GA14891@force.stwing.upenn.edu> Mail-Followup-To: caml users References: <20041206195527.GA32094@draco.skynet> <41B557D4.2000306@inria.fr> <076FEF06-4856-11D9-8195-000D9345235C@inria.fr> <41B5C4C8.9040701@ps.uni-sb.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.4i X-Miltered: at nez-perce with ID 41B5F2DD.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41B5F2DB.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; lovas:01 wlovas:01 stwing:01 upenn:01 caml-list:01 damien:01 wrote:01 rossberg:01 wrote:01 struct:01 struct:01 confuses:01 bool:01 bool:01 module's: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: 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. The following behavior confuses me, too: # let module M = struct let v = fun x -> x end in (M.v 5, M.v true);; - : int * bool = (5, true) This expression has type bool but is here used with type int # let v = let module M = struct let v = fun x -> x end in M.v in (v 5, v true);; ^^^^ This expression has type bool but is here used with type int Why is the type variable generalized inside the `let module's body but not generalized if we pass it to the outside? So the `ref' example above as a counterexample is at the very least hiding some of the story. What's really going on here? William