From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr 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 A5F45BB9A for ; Fri, 28 Oct 2005 13:59:07 +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 j9SBx7sE029604 for ; Fri, 28 Oct 2005 13:59:07 +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 NAA18569 for ; Fri, 28 Oct 2005 13:59:06 +0200 (MET DST) 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 j9SBx4NN007254 for ; Fri, 28 Oct 2005 13:59:05 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id j9SBwvMQ025243; Fri, 28 Oct 2005 20:58:58 +0900 (JST) Date: Fri, 28 Oct 2005 20:59:57 +0900 (JST) Message-Id: <20051028.205957.68033883.garrigue@math.nagoya-u.ac.jp> To: xcforum@free.fr Cc: caml-list@inria.fr Subject: Re: [Caml-list] Question about polymorphic variants From: Jacques Garrigue In-Reply-To: <589B1E9E-D4EC-4E03-9375-30670ED82BEB@free.fr> References: <589B1E9E-D4EC-4E03-9375-30670ED82BEB@free.fr> X-Mailer: Mew version 4.2 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 4362128B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43621288.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 variants:01 ...:98 polymorphic:01 polymorphic:01 expression:01 expression:01 int:01 int:01 jacques: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 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 = 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.) The answer is yes, with a counter-example using the difference in representation between normal arrays and float arrays. 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... Jacques Garrigue