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 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id D746BBC04 for ; Thu, 21 Aug 2008 09:49:47 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgEBABEKrEiCcYARo2dsb2JhbACSFwEBAQEBAQcFCAcRpAOBWQ X-IronPort-AV: E=Sophos;i="4.32,240,1217800800"; d="scan'208";a="14142730" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 20 Aug 2008 21:17:46 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m7KJHjbj004718 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 20 Aug 2008 21:17:46 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgEBABEKrEiCcYARo2dsb2JhbACSFwEBAQEBAQcFCAcRpAOBWQ X-IronPort-AV: E=Sophos;i="4.32,240,1217800800"; d="scan'208";a="14142729" Received: from coriana6.cis.mcmaster.ca ([130.113.128.17]) by mail2-smtp-roc.national.inria.fr with ESMTP; 20 Aug 2008 21:17:45 +0200 Received: from Dura7.UTS.McMaster.CA (dura7.UTS.mcmaster.ca [130.113.196.62]) by coriana6.cis.mcmaster.ca (8.13.7/8.13.7) with ESMTP id m7KJHWZL008168 for ; Wed, 20 Aug 2008 15:17:37 -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 m7KJHCNb027502 for ; Wed, 20 Aug 2008 15:17:12 -0400 Received: from [72.138.80.237] (account carette@univmail.cis.mcmaster.ca HELO [192.168.1.101]) by cgpsrv2.cis.mcmaster.ca (CommuniGate Pro SMTP 4.3.12) with ESMTPSA id 221647073 for caml-list@inria.fr; Wed, 20 Aug 2008 15:17:12 -0400 Message-ID: <48AC6DBC.2040508@mcmaster.ca> Date: Wed, 20 Aug 2008 15:17:16 -0400 From: Jacques Carette Organization: McMaster University User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 To: OCaml Subject: More fun with variants and constraints 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.20.185811 X-PerlMx-Spam: Gauge=IIIIIII, Probability=7%, Report='BODY_SIZE_1800_1899 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 48AC6DD9.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; variants:01 annotations:01 val:01 polymorphism:01 compile:01 constraint:01 constraint:01 int:01 int:01 variant:02 inferred:02 annotation:02 variables:02 mcmaster:02 output:02 [One of my previous difficulties was alleviated by putting variance annotations on my variables, which was not at all obvious from the documentation, other than a vague hint that these are not automatically inferred; I put annotation everywhere in the code below, but +'d is the only one that matters]. In my actual code, I now have some routines that take a huge amount of time to compile (I gave up after 30 minutes). Looking into why that might be, I have produced the following code which shows the issue: type +'a a0 = [`A of 'a ] type +'a a1 = [`B of 'a ] type +'a a2 = [`C of 'a ] type d = [`D of int ] type +'a f1 = ['a a0 | d] type +'a f2 = ['a a1 | d] type (+'a,+'b,+'c) e = ['b a0 | 'a a1 | 'c a2 | d] type (+'a,+'b,+'c) c = ('a,'b,'c) e constraint 'a = [< 'b f1] constraint 'b = [< 'a f2] constraint 'c = [< 'c a2 ] type +'d cc = 'd constraint 'd = [< ('a,'b,'c) c] (* This craps out with 'cc' being an inexact variant let is_cc = function | #cc -> true | _ -> false *) let id_cc (x: 'd cc) = x let build (i:int) : 'd cc = `A (`B (`D i)) let a1 = build 1 ;; The type of a1 is reported as val a1 : [< `A of [< ([< 'a f1 > `D ] as 'b) f2 > `B ] as 'a | `B of 'b | `C of [< 'c a2 ] as 'c & [< 'd a2 ] as 'd & [< 'e a2 ] as 'e & [< 'f a2 ] as 'f | `D of int > `A ] What is puzzling is the type in `C. Why are there 4 (identical!) possibilities? I played around some, and the 4 is equal to the number of constraints in the program. The issue is, in my 'real' code, there are 33 constraints. Simple values now have types that take pages and pages of output. How do I still get all the polymorphism that I want without getting this kind of blow-up? Jacques Carette