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=0.0 required=5.0 tests=none 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 6F2C9BB83 for ; Fri, 1 Sep 2006 21:57:35 +0200 (CEST) Received: from orion.metastack.com (no-dns-yet.demon.co.uk [80.177.38.218] (may be forged)) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k81JvU84006290 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 1 Sep 2006 21:57:34 +0200 Received: from treble (cpc2-cmbg6-0-0-cust535.cmbg.cable.ntl.com [81.107.34.24]) (authenticated bits=0) by orion.metastack.com (8.13.4/8.13.3) with ESMTP id k81JZjTB011233 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Fri, 1 Sep 2006 20:35:45 +0100 From: "David Allsopp" To: "'skaller'" Cc: "'OCaml List'" , "'Chris King'" Subject: RE: [Caml-list] Re: Polymorphic variants question Date: Fri, 1 Sep 2006 20:57:18 +0100 Organization: MetaStack Solutions Ltd. Message-ID: <015101c6ce00$d47c36f0$6a7ba8c0@treble> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 Thread-Index: AcbN9eY7ZeFHz6twSgW9JQlnfvCAdgAA+Fgg In-Reply-To: <1157137228.22787.13.camel@rosella.wigram> X-Miltered: at nez-perce with ID 44F890AA.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; variants:01 compiler:01 bool:01 inference:01 bool:01 compiler:01 checker:01 annotation:01 2006:98 2006:98 eliminates:98 sourceforge:01 wrote:01 wrote:01 polymorphic:01 -----Original Message----- From: skaller [mailto:skaller@users.sourceforge.net] Sent: 01 September 2006 20:00 > On Fri, 2006-09-01 at 14:33 -0400, Chris King wrote: > > On 9/1/06, David Allsopp wrote: > By using: > > let id = function `A -> `A | `C -> `C > > the compiler knows (id x) can include `A > and it can include `C, the case > > (true, `B) > > being returned says the return type can also be `B. > So the return type can be bool followed by `A, `B, or `C. > > Hope that makes sense :) Which is my understanding too - the type of id is [< `A | `C] -> [> `A | `C] which allows x to be "used" in a [> `A | `B | `C] context without actually changing the type of x while type inference is going on. Which, I guess I should've spotted, means I can write: let f (x : [`A | `C]) : bool * [`A | `B | `C] = if x = `A then (true, `B) else (false, (x :> [`A | `B | `C])) Which eliminates id and keeps the whole thing done in the type system (whilst an identity function I'm sure is spotted and removed by the compiler, it's a shame to have it there just to keep the type checker happy!). Incidentally, if I use an annotation free version let f x = if x = `A then (true, `B) else (false, (x : [< `A | `C] :> [> `A | `C])) then the inferred type of x is [< `A | `C > `A ] ... what does that mean? > -- > John Skaller > Felix, successor to C++: http://felix.sf.net Thanks for the help! (incidentally, I don't call labels A, B, C, ... in real code, honest!)