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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id C9759BBC1 for ; Fri, 2 May 2008 20:03:43 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhICAHD0GkjAXQIniGdsb2JhbACRZAEBAQ8gmXCBKw X-IronPort-AV: E=Sophos;i="4.27,427,1204498800"; d="scan'208";a="11767852" Received: from concorde.inria.fr ([192.93.2.39]) by mail1-smtp-roc.national.inria.fr with ESMTP; 02 May 2008 20:03:43 +0200 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m42I3hhp025328 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 2 May 2008 20:03:43 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjQCAEf0GkhQW+UCgWdsb2JhbACRZAEBECCZboEr X-IronPort-AV: E=Sophos;i="4.27,427,1204498800"; d="scan'208";a="12195366" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail3-smtp-sop.national.inria.fr with ESMTP; 02 May 2008 20:03:42 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JrzbT-0000Ai-Jg for caml-list@inria.fr; Fri, 02 May 2008 18:03:27 +0000 Received: from 102.56.101-84.rev.gaoland.net ([84.101.56.102]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 02 May 2008 18:03:27 +0000 Received: from vanicat by 102.56.101-84.rev.gaoland.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 02 May 2008 18:03:27 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: vanicat@debian.org (=?utf-8?Q?R=C3=A9mi?= Vanicat) Subject: Re: question about polymorphic variants Date: Fri, 02 May 2008 20:03:18 +0200 Organization: none Message-ID: <87skx0shw9.dlv@maison.homelinux.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 102.56.101-84.rev.gaoland.net Mail-Copy-To: never User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:zDprMhrFfksjlMS9bv9RvxNGJ+4= Sender: news X-Miltered: at concorde with ID 481B577F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; variants:01 foo:01 foo:01 baz:01 baz:01 polymorphic:01 caml-list:01 int:01 int:01 writes:01 vanicat:01 vanicat:01 coerce:02 coerce:02 match:02 "Jacques Le Normand" writes: > Hello caml-list, > when I try to run the following code: > > > type sometype = > ([ > `Foo of int > | `Bar of int > | `Var of 'a ref > ] as 'a) > type someother = > ([ > `Foo of int > | `Var of 'a ref > ] as 'a) > > let foo : someother = `Foo 5;; > (foo :> sometype) > [...] > > how do I get around this? this can't be done: ref type is neither co-variant or contra-variant : Imagine: let foo : someother = `Var (ref Foo 10);; let bar = (foo :> sometype);; match bar with | Var of r -> r:=`Bar 5;; let baz = match foo with | Var of r -> x then baz will be of type someother, with the `Bar 5 value : this can't be. So you cannot coerce a ref, and so you cannot coerce any value of a type that include a ref. -- RĂ©mi Vanicat