From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 6A20EBB9A for ; Fri, 28 Oct 2005 14:27:00 +0200 (CEST) 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 j9SCQxQm032432 for ; Fri, 28 Oct 2005 14:27:00 +0200 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 OAA19104 for ; Fri, 28 Oct 2005 14:26:59 +0200 (MET DST) Received: from imag.imag.fr (imag.imag.fr [129.88.30.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j9SCQw5P010615 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 28 Oct 2005 14:26:59 +0200 Received: from [147.171.255.214] (mac-clerc.imag.fr [147.171.255.214]) by imag.imag.fr (8.13.0/8.13.0) with ESMTP id j9SCQsoV019070 for ; Fri, 28 Oct 2005 14:26:54 +0200 (CEST) Mime-Version: 1.0 (Apple Message framework v734) In-Reply-To: <20051028.205957.68033883.garrigue@math.nagoya-u.ac.jp> References: <589B1E9E-D4EC-4E03-9375-30670ED82BEB@free.fr> <20051028.205957.68033883.garrigue@math.nagoya-u.ac.jp> Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: quoted-printable From: Xavier Clerc Subject: Re: [Caml-list] Question about polymorphic variants Date: Fri, 28 Oct 2005 14:27:34 +0200 To: caml-list@inria.fr X-Mailer: Apple Mail (2.734) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.6 (imag.imag.fr [129.88.30.1]); Fri, 28 Oct 2005 14:26:54 +0200 (CEST) X-IMAG-MailScanner: Found to be clean X-IMAG-MailScanner-Information: Please contact the ISP for more information X-j-chkmail-Score: MSGID : 43621912.000 on concorde : j-chkmail score : X : 0/20 1 X-Miltered: at nez-perce with ID 43621914.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43621912.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 variants:01 stack:01 stack:01 arrays:01 arrays:01 type-related:01 unboxed:01 variants:01 compiler:01 ...:98 ...:98 polymorphic:01 polymorphic:01 expression:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Le 28 oct. 05 =E0 13:59, Jacques Garrigue a =E9crit : > From: Xavier Clerc > >> Then, I use this function in the following expression : >> >> List.map f >> >> which is in turn inferred as: _[< `Off | `On ] list -> int list >> >> My question is about the meaning of the leading underscore in the >> inferred type (given that I understand the meaning of the underscore >> in an expression such as "Stack.create ()" that is inferred as: '_a >> Stack.t). >> > > This is exactly the same meaning: [< `Off | `On] has some form of > flexibility left, which you might see as a type variable, and as such > it obeys the same rules as type variables. > > An example close to the above one would be: > > # List.map (fun (x,y) -> x+1);; > - : (int * '_a) list -> int list =3D > > Now you might wonder why '_a cannot be polymorphic in the above > example. That is, could there really be a definition of List.map such > that the polymorphic type would be dangerous (causing a segmentation > fault for instance.) This is indeed the question I was asking to myself ... > The answer is yes, with a counter-example using > the difference in representation between normal arrays and float > arrays. In this counter-example, it is not clear to me whether the possible =20 problem is type-related or runtime-related. I mean, would this =20 counter-example still hold if arrays were both boxed or both unboxed ? > Actually, since this counter-example wouldn't apply to the above case > of polymorphic variants, this would probably be safe to leave the > polymorphic variant type as polymorphic... Does this mean that inferring "[< `Off | `On] list -> int list" would =20= be perfectly safe in the example above ? (by saying so, I am not pleading for any compiler change, I am just =20 trying to organize my thoughts) Thanks for you clear (and fast) answer. Regards