From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr 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 7A358BB94 for ; Sun, 2 Oct 2005 18:45:09 +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 j92Gj8nK017990 for ; Sun, 2 Oct 2005 18:45:08 +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 SAA24029 for ; Sun, 2 Oct 2005 18:45:07 +0200 (MET DST) Received: from anthony.ics.uci.edu (anthony.ics.uci.edu [128.200.39.241]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id j92Gj6VQ032419 for ; Sun, 2 Oct 2005 18:45:07 +0200 Received: (qmail 2242 invoked by uid 1000); 2 Oct 2005 16:45:08 -0000 Date: Sun, 2 Oct 2005 09:45:08 -0700 From: Christian Stork To: Jean-Marie Gaillourdet Cc: Caml List Subject: Re: [Caml-list] Using Polymorphic Variants Message-ID: <20051002164508.GA1686@anthony.ics.uci.edu> Mail-Followup-To: Jean-Marie Gaillourdet , Caml List References: <20051002000609.GA30761@anthony.ics.uci.edu> <433F9DBE.6020509@gaillourdet.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <433F9DBE.6020509@gaillourdet.net> X-Archive: encrypt User-Agent: Mutt/1.5.11 X-Miltered: at concorde with ID 43400E94.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 43400E92.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 variants:01 variants:01 coerced:01 extensively:01 coercions:01 coercions:01 val:01 val:01 'a-:01 'a-:01 subtype:01 coerced:01 subtype:01 ...:98 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Sun, Oct 02, 2005 at 10:43:42AM +0200, Jean-Marie Gaillourdet wrote: > Christian Stork schrieb: > > Basic Question: > > Why aren't polymorphic variants coerced by default? > I guess there is some undecidability involved. My guess too, but I'd like to be sure. ;-) > > I am automatically generating some code that uses polymorphic variants > > extensively. The inferred types are very complicated. Unfortunatly, at > > some points in my code coercions are needed for it to compile. Since I > > don't have the types available when I generate the code (and I don't > > think it's possible to refer to inferred types in coercions) I can't > > coerce explicitly. I'd like to be able to say something like: > > ... f (x: type_of_x :> type_expected_by_f) ... > Isn't it possible to write something like that: > (f: 'a) (x: type_of_x :> 'a) > I didn't test that trick. Nice idea. Let's see: # type ab = [ `Apple | `Banana ] type abo = [ ab | `Orange] let f (x:abo) = match x with #ab -> "ab" | #abo -> "orange" let a = (`Apple:ab);; type ab = [ `Apple | `Banana ] type abo = [ `Apple | `Banana | `Orange ] val f : abo -> string = val a : ab = `Apple # f (a:>abo);; - : string = "ab" # (f:'a->_) (a:ab:>'a);; Characters 10-20: (f:'a->_) (a:ab:>'a);; ^^^^^^^^^^ Type ab = [ `Apple | `Banana ] is not a subtype of type abo = [ `Apple | `Banana | `Orange ] The first variant type does not allow tag(s) `Orange # (f:'a->_) (a:>'a);; Characters 11-12: (f:'a->_) (a:>'a);; ^ This expression cannot be coerced to type abo = [ `Apple | `Banana | `Orange ]; it has type ab but is here used with type abo The first variant type does not allow tag(s) `Orange I'm confused about the error message saying that ab is not a subtype of abo. I thought it is... -- Chris Stork <> Support eff.org! <> http://www.ics.uci.edu/~cstork/ OpenPGP fingerprint: B08B 602C C806 C492 D069 021E 41F3 8C8D 50F9 CA2F