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=1.7 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST,DNS_FROM_RFC_WHOIS autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 92A5DBB84 for ; Fri, 18 Jul 2008 15:09:02 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AugAAEMzgEjOvjGsgGdsb2JhbACSPQEBCQcCBAkRA5xC X-IronPort-AV: E=Sophos;i="4.31,210,1215381600"; d="scan'208";a="13242439" Received: from web54602.mail.re2.yahoo.com ([206.190.49.172]) by mail2-smtp-roc.national.inria.fr with SMTP; 18 Jul 2008 15:09:01 +0200 Received: (qmail 46114 invoked by uid 60001); 18 Jul 2008 13:09:01 -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=hR9/32zHfMTQzpkt1aW7W1o0EcyK9kAbqTcoLFgUY2f/Lz4MJgvzvec2YcWuq47wWPkDNbQEhaioSAvlVurteJDK8jJF3wkkc2PMBsng8I6BD6DH5F/n4rB8sfGIYPzEnMn7eDodQZhMkm0I1wK4+N2ReVGUAKw0/mPYqPA5kYY=; Received: from [212.13.63.63] by web54602.mail.re2.yahoo.com via HTTP; Fri, 18 Jul 2008 06:09:01 PDT X-Mailer: YahooMailWebService/0.7.218 Date: Fri, 18 Jul 2008 06:09:01 -0700 (PDT) From: Dario Teixeira Subject: Re: [Caml-list] Troublesome nodes To: Jacques Garrigue Cc: caml-list@yquem.inria.fr In-Reply-To: <20080718.112750.233079116.garrigue@math.nagoya-u.ac.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-ID: <299457.46023.qm@web54602.mail.re2.yahoo.com> X-Spam: no; 0.00; nodes:01 node:01 compiler:01 node:01 sig:01 val:01 val:01 struct:01 seq:01 seq:01 syntax:01 syntax:01 struct:01 unbound:01 rec:01 Hi, Thanks once more for your help, Jacques. I had no idea this problem would prove to be such a challenge! > So if you write > > type (+'a, 'b) t =3D private 'a constraint 'a =3D [< super_node_t ] > > then you must write (x : (_,_) t :> [> ]) if you want to use pattern > matching on x. The 'private' declaration you suggested does work on some simpler examples, but the 3.11 compiler won't accept it for the Node module. This is the cod= e: module rec Node: sig type nonlink_node_t =3D [ `Text of string | `Bold of Node.super_nod= e_t list ] type link_node_t =3D [ `See of string | `Mref of string * nonlink_n= ode_t list ] type super_node_t =3D [ nonlink_node_t | link_node_t ] type (+'a, 'b) t =3D private 'a constraint 'a =3D [< super_node_t ] val text: string -> ([> nonlink_node_t], [> `Basic]) t val bold: ([< super_node_t], 'a) t list -> ([> nonlink_node_t], 'a)= t val see: string -> ([> link_node_t], [> `Basic]) t val mref: string -> (nonlink_node_t, 'a) t list -> ([> link_node_t]= , [> `Complex]) t val make_basic: ('a, [< `Basic]) t -> ('a, [`Basic]) t val make_complex: ('a, [< `Basic | `Complex]) t -> ('a, [`Complex])= t end =3D struct type nonlink_node_t =3D [ `Text of string | `Bold of Node.super_nod= e_t list ] type link_node_t =3D [ `See of string | `Mref of string * nonlink_n= ode_t list ] type super_node_t =3D [ nonlink_node_t | link_node_t ] type (+'a, 'b) t =3D 'a constraint 'a =3D [< super_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) let make_basic n =3D n let make_complex n =3D n end And this is the error: Type declarations do not match: type (+'a, 'b) t =3D ('a, 'b) Node.t constraint 'a =3D [< super_node_t ] is not included in type (+'a, 'b) t =3D private 'a constraint 'a =3D [< super_node_t ] > By the way, I forgot to mention that aliases (as keyword) of those > were not allowed until now, so I have to fix it to make the syntax for > private rows work. (There are useful examples using this syntax.) > > type ('a, 'b) t =3D private [< super_node_t ] as 'a With 3.11+dev12, the above declaration produces a "Unbound type parameter .= ." error. When you say you have to fix it, do you mean this will actually be a valid declaration in 3.11 final? And will this solution allow for easier pattern-matching of Node values, without the need for coercion? Speaking of coercion, the exact syntax for it in combination with '#' patterns elludes me. Take for example a simple, "identity", Node-to-Node module listed below. How can coercion be applied? module Node_to_Node =3D struct open Node let rec convert_nonlink_node =3D function | `Text txt -> text txt | `Bold inl -> bold (List.map convert_super_nod= e inl) and convert_link_node =3D function | `Mref (ref, inl) -> mref ref (List.map convert_nonli= nk_node inl) | `See ref -> see ref and convert_super_node =3D function | #nonlink_node_t as node -> (convert_nonlink_node node : ('a= , 'b) t :> (super_node_t, 'b) t) | #link_node_t as node -> convert_link_node node end Best regards, Dario Teixeira =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