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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id E41A1BBAF for ; Sat, 12 Jul 2008 20:21:11 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqYAAGWTeEjOvjGtfGdsb2JhbACSLAEBCwUCBgcRA5Yo X-IronPort-AV: E=Sophos;i="4.30,350,1212357600"; d="scan'208";a="27268432" Received: from web54603.mail.re2.yahoo.com ([206.190.49.173]) by mail4-smtp-sop.national.inria.fr with SMTP; 12 Jul 2008 20:21:10 +0200 Received: (qmail 40708 invoked by uid 60001); 12 Jul 2008 18:21:09 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-Mailer:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=6sXkIb6cgCdlHWbdwHYFWwPyPWKJLB7/c4jxKER1mj9jxKPDXTgJWc9ifKF6Lo2c5lEsXj5kgqKjr1n+fbNKhzS3vwvcS2wrYigQMKcJ+M8BGIsT1f3U72FNBykkTl8SKfPKcdOi9K5BjuqCOloavyu0oyBXrAEUayWRWM/b35k=; Received: from [212.13.62.222] by web54603.mail.re2.yahoo.com via HTTP; Sat, 12 Jul 2008 11:21:09 PDT X-Mailer: YahooMailWebService/0.7.199 Date: Sat, 12 Jul 2008 11:21:09 -0700 (PDT) From: Dario Teixeira Subject: Re: [Caml-list] Troublesome nodes To: Wolfgang Lux Cc: Jeremy Yallop , caml-list@yquem.inria.fr In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-ID: <761520.40658.qm@web54603.mail.re2.yahoo.com> X-Spam: no; 0.00; nodes:01 node:01 compiler:01 nodes:01 node:01 sig:01 val:01 val:01 struct:01 seq:01 seq:01 foo:01 foo:01 struct:01 intersection:01 Hi, Thank you all for your help! I think we're almost there: with Wolfgang's suggestion, the Node module complies with the original constraints, as the code below shows: (the compiler complains -- as it should! -- when on the last line I try to nest two link nodes directly) module rec Node: sig type nonlink_node_t =3D [ `Text of string | `Bold of Node.super_node_t = list ] type link_node_t =3D [ `See of string | `Mref of string * nonlink_node_= t list ] type super_node_t =3D [ nonlink_node_t | link_node_t ] val text: string -> nonlink_node_t val bold: [< super_node_t] list -> nonlink_node_t val see: string -> link_node_t val mref: string -> nonlink_node_t list -> link_node_t end =3D struct type nonlink_node_t =3D [ `Text of string | `Bold of Node.super_node_t = list ] type link_node_t =3D [ `See of string | `Mref of string * nonlink_node_= t list ] type super_node_t =3D [ nonlink_node_t | link_node_t ] let text txt =3D `Text txt let bold seq =3D `Bold (seq :> super_node_t list) let see ref =3D `See ref let mref ref seq =3D `Mref (ref, seq) end open Node let foo1 =3D text "foo" (* valid *) let foo2 =3D bold [text "foo"] (* valid *) let foo3 =3D mref "ref" [text "foo"] (* valid *) let foo4 =3D mref "ref" [see "ref"] (* invalid *) Now, the icing on the cake would be the possibility to build a Node_to_Node set of functions without code duplication. Ideally, I would like to do something as follows: module Node_to_Node =3D struct open Node let rec convert_nonlink_node =3D function | `Text txt -> Node.text txt | `Bold seq -> Node.bold (List.map convert_super_node seq) and convert_link_node =3D function | `See ref -> Node.see ref | `Mref (ref, seq) -> Node.mref ref (List.map convert_nonlink_node= seq) and convert_super_node node =3D match node with | #nonlink_node_t -> (convert_nonlink_node node :> super_node_t) | #link_node_t -> (convert_link_node node :> super_node_t) end But this fails on the last line: Error: This expression has type [< `Bold of 'a list & Node.super_node_t list | `Text of string ] as 'a but is here used with type [< `Mref of string * 'a list | `See of string ] These two variant types have no intersection Do you see any way around it? Thanks again for all your time and attention! Cheers, Dario =0A=0A=0A __________________________________________________________= =0ANot happy with your email address?.=0AGet the one you really want - mill= ions of new email addresses available now at Yahoo! http://uk.docs.yahoo.co= m/ymail/new.html