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 5158ABC84 for ; Thu, 31 Mar 2005 03:26:56 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j2V1QtFe004900 for ; Thu, 31 Mar 2005 03:26:55 +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 DAA17263 for ; Thu, 31 Mar 2005 03:26:55 +0200 (MET DST) Received: from out1.smtp.messagingengine.com (out1.smtp.messagingengine.com [66.111.4.25]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j2V1QsXL004893 for ; Thu, 31 Mar 2005 03:26:55 +0200 Received: from frontend3.messagingengine.com (frontend3.internal [10.202.2.152]) by frontend1.messagingengine.com (Postfix) with ESMTP id 362D2C6B78A; Wed, 30 Mar 2005 20:26:53 -0500 (EST) X-Sasl-enc: 2V0YPAnUyrCxKIqIRMPKBg 1112232413 Received: from [172.16.112.115] (burnham.ljcrf.edu [192.231.106.2]) by frontend3.messagingengine.com (Postfix) with ESMTP id 28441247F3; Wed, 30 Mar 2005 20:26:47 -0500 (EST) Date: Wed, 30 Mar 2005 17:26:38 -0800 (PST) From: Martin Jambon X-X-Sender: martin@localhost To: yminsky@cs.cornell.edu Cc: Jacques Garrigue , Subject: Re: [Caml-list] When is a function polymorphic? In-Reply-To: <891bd339050330165142478f37@mail.gmail.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde with ID 424B51DF.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 424B51DE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 yaron:01 minsky:01 notation:01 foo:01 converts:01 foo:01 variants:01 const:01 const:01 val:01 ...:98 wrote:01 polymorphic:01 polymorphic:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: On Wed, 30 Mar 2005, Yaron Minsky wrote: > 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? With polymorphic variants, you can do something like this: # type const = [ `B of int | `C ];; type const = [ `B of int | `C ] # type 'a poly = [ `A of 'a | const ];; type 'a poly = [ `A of 'a | `B of int | `C ] # let f : 'a poly -> unit poly= function `A _ -> `A () | #const as x -> x;; val f : 'a poly -> unit poly = Martin -- Martin Jambon, PhD http://martin.jambon.free.fr