From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.9 required=5.0 tests=DNS_FROM_RFC_ABUSE, SPF_NEUTRAL autolearn=disabled version=3.1.3 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 EBEE1BB83 for ; Fri, 1 Sep 2006 20:33:54 +0200 (CEST) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.189]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k81IXsSL027835 for ; Fri, 1 Sep 2006 20:33:54 +0200 Received: by nf-out-0910.google.com with SMTP id l37so757253nfc for ; Fri, 01 Sep 2006 11:33:54 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=rnxlcht865/ucwB9ouYdSs4iRiyR7jMaqGRH/LvTpx+qCrj+xD6XaAnvj7o5KRGjLSUn0BddDRLp3EC6/F0489vvH865sEmEqTvERLps/R4oXSOs84aWBji9Bh7LVudnCWZLnFdKVSijCzckWq6sogq306sn3HZHeDiNdi0FTe8= Received: by 10.48.48.15 with SMTP id v15mr3401101nfv; Fri, 01 Sep 2006 11:33:54 -0700 (PDT) Received: by 10.49.49.16 with HTTP; Fri, 1 Sep 2006 11:33:53 -0700 (PDT) Message-ID: <875c7e070609011133udd506c7v223d8ece952b95ae@mail.gmail.com> Date: Fri, 1 Sep 2006 14:33:53 -0400 From: "Chris King" To: "David Allsopp" Subject: Re: Polymorphic variants question Cc: "OCaml List" In-Reply-To: <012901c6cdec$64edf490$6a7ba8c0@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <012901c6cdec$64edf490$6a7ba8c0@treble> X-j-chkmail-Score: MSGID : 44F87D12.001 on nez-perce : j-chkmail score : X : 0/20 1 X-Miltered: at nez-perce with ID 44F87D12.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; variants:01 bool:01 compiler:01 val:01 bool:01 wrote:01 polymorphic:01 coercion:01 clarify:02 let:03 let:03 perhaps:04 somewhat:05 chris:05 chris:05 On 9/1/06, David Allsopp wrote: > Now, if I try to constrain it to what I'm after with > > let (f : [`A | `C] -> bool * [`A | `B | `C]) = fun x -> ... > > then I get a type error unless I change > (false, x) > to > (false, id x) > with > let id = function `A -> `A | `C -> `C > > Is there a better way of writing this? Yes, you can use the coercion operator to tell the compiler to expand the type of x to include `B: # let f (x: [`A | `C]) = if x = `A then (true, `B) else (false, (x :> [`A | `B | `C])) val f : [ `A | `C ] -> bool * [ `A | `B | `C ] = Perhaps someone else can clarify how this accomplishes the same thing as your id function, as my understanding of type theory is somewhat rudimentary. - Chris King