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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 58671BB84 for ; Thu, 14 Aug 2008 04:19:15 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkIBAGwzo0iCcUBThWdsb2JhbACRcwEBAQoFAgYHEaQSgVU X-IronPort-AV: E=Sophos;i="4.32,205,1217800800"; d="scan'208";a="28208963" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 14 Aug 2008 04:19:15 +0200 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m7E2JE4g024171 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 14 Aug 2008 04:19:14 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkIBAGwzo0iCcUBThWdsb2JhbACRcwEBAQoFAgYHEaQSgVU X-IronPort-AV: E=Sophos;i="4.32,205,1217800800"; d="scan'208";a="28208958" Received: from sigma957.cis.mcmaster.ca ([130.113.64.83]) by mail4-smtp-sop.national.inria.fr with ESMTP; 14 Aug 2008 04:19:13 +0200 Received: from Dura7.UTS.McMaster.CA (dura7.UTS.mcmaster.ca [130.113.196.62]) by sigma957.cis.mcmaster.ca (8.13.7/8.13.7) with ESMTP id m7E2IpWX001167 for ; Wed, 13 Aug 2008 22:19:11 -0400 (EDT) Received: from cgpsrv2.cis.mcmaster.ca (univmail.CIS.McMaster.CA [130.113.64.46]) by Dura7.UTS.McMaster.CA (8.13.7/8.13.7) with ESMTP id m7E2IZpC011156 for ; Wed, 13 Aug 2008 22:18:35 -0400 Received: from [72.138.80.237] (account carette@univmail.cis.mcmaster.ca HELO [192.168.1.100]) by cgpsrv2.cis.mcmaster.ca (CommuniGate Pro SMTP 4.3.12) with ESMTPSA id 220884847 for caml-list@inria.fr; Wed, 13 Aug 2008 22:18:35 -0400 Message-ID: <48A395FA.2050704@mcmaster.ca> Date: Wed, 13 Aug 2008 22:18:34 -0400 From: Jacques Carette User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 To: caml-list@inria.fr Subject: Why is this coercion necessary? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version-Mac: 5.4.2.338381, Antispam-Engine: 2.6.0.325393, Antispam-Data: 2008.8.14.20416 X-PerlMx-Spam: Gauge=IIIIIII, Probability=7%, Report='BODY_SIZE_1100_1199 0, BODY_SIZE_5000_LESS 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __USER_AGENT 0' X-Miltered: at concorde with ID 48A39622.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; 'n':01 intersection:01 intersection:01 type-checker:01 coercions:01 polluting:01 'recursive:01 bug:01 coercions:01 coercion:01 coercion:01 variant:02 expression:02 match:02 match:02 Here is a much simplified version from a (much) larger problem I have recently encountered: type 'a a = [`A of 'a b] and 'a b = [`B of 'a a] and 'a c = [`C ] type 'a d = [ 'a a | 'a b | 'a c] type e = e d # this code gives an error (details below) let f1 (x:e) : e = match x with | `A n -> n | `B n -> n | `C -> `C # this works let f2 (x:e) : e = match x with | `A n -> (n :> e) | `B n -> (n :> e) | `C -> `C f1 gives an error on the "| `B n -> n" line, pointing to the second 'n' with This expression has type e a but is used with type e b These two variant types have no intersection Indeed, they have no intersection, but they have a union! That is what it seems the coercion in f2 'forces' the type-checker to realize, and all works fine. But of course, such coercions end up polluting my code all over the place (since the actual example is made of 9 types with 20 tags in total, and the 'recursive knot' requires 2 parameters to close properly). So, is this a bug? Is there a way to avoid these coercions? Jacques