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.6 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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 93D92BB84 for ; Mon, 14 Jul 2008 20:52:51 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgwBAHI9e0jOvjGufGdsb2JhbACSLgEBCwUCBgcRA5ka X-IronPort-AV: E=Sophos;i="4.30,360,1212357600"; d="scan'208";a="27313672" Received: from web54604.mail.re2.yahoo.com ([206.190.49.174]) by mail4-smtp-sop.national.inria.fr with SMTP; 14 Jul 2008 20:52:50 +0200 Received: (qmail 75920 invoked by uid 60001); 14 Jul 2008 18:52:50 -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=lv/h2FU5gtDy5e09xfYLgLH864/HyNaVrbGo2jr2JM/aDyxYlW67CvDo19Cw4TXyKNCRfYWJueGaiW7H3sgL5jZ1VY02gsgJBNj+l1QUC0X5Oh2T05vCT5FU6xQx6HAAWxNjQz7Bs+Rtf0GKNvvlMk4ccW4HTF76uIM+HHQ4gUM=; Received: from [212.13.63.137] by web54604.mail.re2.yahoo.com via HTTP; Mon, 14 Jul 2008 11:52:49 PDT X-Mailer: YahooMailWebService/0.7.199 Date: Mon, 14 Jul 2008 11:52:49 -0700 (PDT) From: Dario Teixeira Subject: Re: [Caml-list] Troublesome nodes To: caml-list@yquem.inria.fr Cc: Jon Harrop In-Reply-To: <790934.91073.qm@web54606.mail.re2.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-ID: <831.74975.qm@web54604.mail.re2.yahoo.com> X-Spam: no; 0.00; nodes:01 'constraint':01 nodes:01 orthogonal:01 node:01 ocamlc:01 node:01 ocamlc:01 foo:01 module's:01 sig:01 val:01 val:01 struct:01 seq:01 Hi, After some trial and error in the top-level, I think I got the hang of the 'constraint' declaration (is there other documentation for it besides the couple of lines in the Reference Manual?). Note that besides the already discussed link/nonlink distinction between nodes, there is now also an orthogonal distinction between basic/complex nodes (all nodes except for Mref are basic; any document that uses Mref thus becomes "contaminated" and cannot use basic-only functions; the inverse, however, is not true). I took advantage of Jon's suggestion of boxing all return types into a single Node.t to implement this latter distinction using phantom types (is there even an alternative technique?). Now, the code below seems correct, and running "ocamlc -i node.ml" produces the type signatures you would expect, and without error messages. However, running "ocamlc -c node.ml" fails with a "The type of this expression conta= ins type variables that cannot be generalized" error on the declaration of foo3= . Moreover, if you comment out the top-level declarations and try to compile only the module declaration, you will also get different results whether yo= u run "ocamlc -i" or "ocamlc -c". The former displays the module's signature as expected, but the latter produces this error message: 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 ] I find this behaviour a bit odd. What is going on? Best regards, Dario Teixeira 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 ] 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: ([< super_node_t], [< `Basic]) t -> (super_node_t, [`Ba= sic]) t val make_complex: ([< super_node_t], [< `Basic | `Complex]) t -> (super= _node_t, [`Complex]) 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 ] 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 :> (super_node_t, [`Basic]) t) let make_complex n =3D (n :> (super_node_t, [`Complex]) t) end open Node let foo1 =3D text "ola" let foo2 =3D bold [text "ola"] let foo3 =3D mref "ref" [foo1; foo2] let basic1 =3D make_basic foo1 let basic2 =3D make_basic foo2 let complex1 =3D make_complex foo1 let complex2 =3D make_complex foo2 let complex3 =3D make_complex foo3 =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