From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 7C618BCA8 for ; Thu, 31 Mar 2005 03:16:00 +0200 (CEST) Received: from ux9.sp.cs.cmu.edu (UX9.SP.CS.CMU.EDU [128.2.220.166]) by concorde.inria.fr (8.13.0/8.13.0) with SMTP id j2V1Fx4N003893 for ; Thu, 31 Mar 2005 03:16:00 +0200 Received: from c-24-3-154-200.client.comcast.net ([24.3.154.200]) by ux9.sp.cs.cmu.edu id aa11383; 30 Mar 2005 20:15 EST Received: from ecc by stratocaster.home with local (Exim 4.50) id 1DGoHh-0004DH-8s; Wed, 30 Mar 2005 20:15:45 -0500 Date: Wed, 30 Mar 2005 20:15:45 -0500 To: caml-list@yquem.inria.fr, caml-list@inria.fr Subject: Re: [Caml-list] When is a function polymorphic? Message-ID: <20050331011545.GA16178@localhost> Mail-Followup-To: caml-list@yquem.inria.fr, caml-list@inria.fr References: <891bd33905033014311636570a@mail.gmail.com> <20050331.093724.70528102.garrigue@math.nagoya-u.ac.jp> <891bd339050330165142478f37@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <891bd339050330165142478f37@mail.gmail.com> User-Agent: Mutt/1.5.6+20040907i From: Eric Cooper X-Miltered: at concorde with ID 424B4F4F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 yaron:01 minsky:01 foo:01 converts:01 foo:01 constructors:01 bool:01 ...:98 ...:98 wrote:01 polymorphic:01 cleanly:01 int:01 int: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=none autolearn=disabled version=3.0.2 X-Spam-Level: On Wed, Mar 30, 2005 at 07:51:04PM -0500, Yaron Minsky wrote: > 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? If you can accept another level of constructors, this will work: type 'a foo = A of 'a | NotA of bar and bar = B of int | C of string | D of bool | ... function A _ -> A () | NotA x -> NotA x -- Eric Cooper e c c @ c m u . e d u