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 D5D21BC84 for ; Thu, 31 Mar 2005 02:51:06 +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 j2V0p6OD006048 for ; Thu, 31 Mar 2005 02:51:06 +0200 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 CAA17170 for ; Thu, 31 Mar 2005 02:51:05 +0200 (MET DST) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.206]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2V0p5Ij006043 for ; Thu, 31 Mar 2005 02:51:05 +0200 Received: by wproxy.gmail.com with SMTP id 69so364340wri for ; Wed, 30 Mar 2005 16:51:04 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=QRLFr838mE8EQH33QGeFhZuMkkF3o4pVfqgc3KzGk+aHIu7EZiUTcTyGvCXE5hfaeenBsRpkD6nVw9v0OEgoIj5rTbbuAJPRFjpvwAlWFnw5qThKrGKKiXbPavsP0atqyRoAzi9p10SqMlYl8ljvIf59xlZIgsXpxka9WxtGn/k= Received: by 10.54.8.48 with SMTP id 48mr381476wrh; Wed, 30 Mar 2005 16:51:04 -0800 (PST) Received: by 10.54.2.79 with HTTP; Wed, 30 Mar 2005 16:51:04 -0800 (PST) Message-ID: <891bd339050330165142478f37@mail.gmail.com> Date: Wed, 30 Mar 2005 19:51:04 -0500 From: Yaron Minsky Reply-To: yminsky@cs.cornell.edu To: Jacques Garrigue Subject: Re: [Caml-list] When is a function polymorphic? Cc: caml-list@inria.fr In-Reply-To: <20050331.093724.70528102.garrigue@math.nagoya-u.ac.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit References: <891bd33905033014311636570a@mail.gmail.com> <20050331.093724.70528102.garrigue@math.nagoya-u.ac.jp> X-Miltered: at nez-perce with ID 424B497A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 424B4979.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; yaron:01 minsky:01 yminsky:01 caml-list:01 typechecker:01 unifying:01 notation:01 foo:01 converts:01 foo:01 yaron:01 ...:98 wrote:01 pat:01 polymorphic:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.2 X-Spam-Level: On Thu, 31 Mar 2005 09:37:24 +0900 (JST), Jacques Garrigue wrote: > > The typechecker does something special about "as x" patterns. > Namely, rather than unifying the type of x with the type of the whole > input, it types the aliased pattern twice, and only unifies type > parameters which appear in the pattern. So this means that > # function Some _ as x -> x | None -> Some () ;; > - : unit option -> unit option = > since the type parameter appears in the argument to Some, while > # function Some x -> Some () | None as x -> x;; > - : 'a option -> unit option = > since it doesn't appear in None. > This clever typing only happens with " as " patterns, so > your second example gets the standard result (it is assumed that x > could be anything, including Some, as the typing does not use the > result of the exhaustiveness analysis.) > I think I screwed up the original examples a bit. I think the effect I'm looking at doesn't depend on the "as" notation in particular. Here's another example that doesn't use "as": # function Some x -> Some () | None -> None;; - : 'a option -> unit option = # function Some x -> Some () | x -> x;; - : unit option -> unit option = The reason I want this is for the following example. Consider some complicated union type with a single parameter: type 'a foo = A of 'a | B of int | C of string * string | ... | ZZ of float I want a function that converts an 'a foo to a unit foo. I tried to write it this way: function A _ -> A () | x -> x But this ends up having type: unit foo -> unit foo, which isn't what I want at all. Any idea of how to achieve this cleanly? Yaron