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 nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 8D63ABB84 for ; Thu, 29 Jun 2006 06:30:10 +0200 (CEST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k5T4U9IY005947 for ; Thu, 29 Jun 2006 06:30:10 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.6) with ESMTP id k5T3bMD1002242; Thu, 29 Jun 2006 12:37:22 +0900 (JST) Date: Thu, 29 Jun 2006 12:37:18 +0900 (JST) Message-Id: <20060629.123718.71847699.garrigue@math.nagoya-u.ac.jp> To: "Seth J. Fogarty" Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Question on Variant Types From: Jacques Garrigue In-Reply-To: References: X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 44A35751.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; foo:01 foo:01 rec:01 subtypes:01 subtyping:01 foobar:01 foobar:01 wrote:01 caml-list:01 jacques:01 jacques:01 int:01 int:01 variant:02 variant:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DNS_FROM_RFC_ABUSE autolearn=disabled version=3.0.3 On 6/29/06, Seth J. Fogarty wrote: > If you have time, I have one more question I can't seem to solve. Which > quite possibly has as simple an answer as the other two. You've been very > helpful so far, and I don't want to impose, so feel free to let me know if > you've not the time. > > type foo = [`A of int | `B | 'D of foo] > type bar = [`A of int | `C of foo * bar | 'D of bar] > > let rec occurs i x = > match x with > |`A j -> i = j > |`C (foo, bar) -> (occurs i foo) or (occurs i bar) > |_ -> false > > I would like occurs to work on bars and foos. But as it is, occurs won't > work on either, because it assigns the `C variant the type "`C of 'b * 'b". > Even if I spell out `D and `B, I cannot get it to accept. As long as foo and bar are two subtypes of a common type, you can still solve the problem by defining that type and using subtyping: type foobar = [`A of int | `B | `C of foobar * foobar | `D of foobar] let occurs_foo i x = occurs i (x : foo :> foobar) let occurs_bar i x = occurs i (x : bar :> foobar) Jacques Garrigue