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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id BA587BBAF for ; Sat, 12 Jul 2008 15:25:44 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am4AAMdNeEiCcYARomdsb2JhbACSLAEBAQEBCAUGCRGWMg X-IronPort-AV: E=Sophos;i="4.30,349,1212357600"; d="scan'208";a="15053452" Received: from coriana6.cis.mcmaster.ca ([130.113.128.17]) by mail3-smtp-sop.national.inria.fr with ESMTP; 12 Jul 2008 15:25:43 +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 m6CDPaJT013118; Sat, 12 Jul 2008 09:25:41 -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 m6CDP4kM013499; Sat, 12 Jul 2008 09:25:04 -0400 Received: from [72.138.80.237] (account carette@univmail.cis.mcmaster.ca HELO [192.168.1.100]) by cgpsrv2.cis.mcmaster.ca (CommuniGate Pro SMTP 4.3.12) with ESMTPSA id 217590453; Sat, 12 Jul 2008 09:25:05 -0400 Message-ID: <4878B0B2.4020501@mcmaster.ca> Date: Sat, 12 Jul 2008 09:25:06 -0400 From: Jacques Carette Organization: McMaster University User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: Dario Teixeira Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Troublesome nodes References: <197205.74716.qm@web54603.mail.re2.yahoo.com> In-Reply-To: <197205.74716.qm@web54603.mail.re2.yahoo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version-Mac: 5.4.2.338381, Antispam-Engine: 2.6.0.325393, Antispam-Data: 2008.7.12.131103 X-PerlMx-Spam: Gauge=IIIIIII, Probability=7%, Report='BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, ECARD_KNOWN_DOMAINS 0, __BOUNCE_CHALLENGE_SUBJ 0, __CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __FRAUD_419_REFNUM 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __PHISH_SPEAR_ACCOUNT_2 0, __SANE_MSGID 0, __USER_AGENT 0' X-Spam: no; 0.00; nodes:01 recursive:01 node:01 annotations:01 metaocaml:01 ocaml:01 node:01 sig:01 val:01 val:01 struct:01 seq:01 seq:01 compiler:01 subset:01 The ingenious use of a recursive module signature seems to be the source of the problem here. If one defines 'bar' inside the module Node, it works fine [but is clearly useless]. What surprises me is that the code (below) also gives the exact same error. In other contexts, I have managed to get such annotations (see the definition of the bold function) to 'work', but not here. I am quite puzzled by this, so if you do get an answer to your question offl-ist, I would appreciate if you could forward it on. Jacques PS: because I am actually using metaocaml for other projects, I am using ocaml 3.09 for my tests, so it is possible that something is different in 3.10. module Node : sig type nonlink_node_t type link_node_t type super_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 = struct type 'a p1 = [ `Text of string | `Bold of 'a list ] type 'a p2 = [ `See of string | `Mref of string * 'a p1 list ] type 'a p3 = [ 'a p1 | 'a p2 ] type super_node_t = super_node_t p3 type nonlink_node_t = super_node_t p1 type link_node_t = super_node_t p2 let text txt = `Text txt let bold seq = `Bold (seq :> super_node_t list) let see ref = `See ref let mref ref seq = `Mref (ref, seq) end;; Dario Teixeira wrote: > Hi, > > Thanks Jeremy, that's quite ingenious. However, I've hit a problem in the > definition of the constructor functions (the full code + compiler error > is below). Now, I know that nonlink_node_t is a subset of super_node_t, > and therefore any variant valid for nonlink_node_t is also acceptable for > super_node_t. But how do I tell this to the compiler? (Note that having > users of the module manually casting types with :> is something I would > rather avoid). > > Thanks again, > Dario > > > module rec Node: > sig > type nonlink_node_t = [ `Text of string | `Bold of Node.super_node_t list ] > type link_node_t = [ `See of string | `Mref of string * nonlink_node_t list ] > type super_node_t = [ 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 = > struct > type nonlink_node_t = [ `Text of string | `Bold of Node.super_node_t list ] > type link_node_t = [ `See of string | `Mref of string * nonlink_node_t list ] > type super_node_t = [ nonlink_node_t | link_node_t ] > > let text txt = `Text txt > let bold seq = `Bold seq > let see ref = `See ref > let mref ref seq = `Mref (ref, seq) > end > > open Node > let foo = text "foo" > let bar = bold [text "bar"] > > > Error: This expression has type Node.nonlink_node_t > but is here used with type Node.super_node_t > The first variant type does not allow tag(s) `Mref, `See > > > > > __________________________________________________________ > Not happy with your email address?. > Get the one you really want - millions of new email addresses available now at Yahoo! http://uk.docs.yahoo.com/ymail/new.html > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >