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 7AC7BBBAF for ; Mon, 7 Jul 2008 15:48:45 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArsAAOe7cUjOvjGsfGdsb2JhbACSWwEBCwUCBgcRA5tV X-IronPort-AV: E=Sophos;i="4.30,316,1212357600"; d="scan'208";a="14886870" Received: from web54602.mail.re2.yahoo.com ([206.190.49.172]) by mail3-smtp-sop.national.inria.fr with SMTP; 07 Jul 2008 15:48:27 +0200 Received: (qmail 17460 invoked by uid 60001); 7 Jul 2008 13:48:26 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=WyRCtFOWs0qJeNiE+PNaIRlHiK62msMHlWRILl0llcAmtMYbhZg+uXgeulFnHs/1q9r+WVa9cCpZlSYqLGxCTJHVA+nFMOGnw2D51PDQuWNGLA3tuqmsRJPvNuFVzStjJyry1SjWsi/kiD9PfAbi6UbxjvsU6q/QHTwV80Ji3fQ=; Received: from [212.13.63.80] by web54602.mail.re2.yahoo.com via HTTP; Mon, 07 Jul 2008 06:48:26 PDT X-Mailer: YahooMailWebService/0.7.199 Date: Mon, 7 Jul 2008 06:48:26 -0700 (PDT) From: Dario Teixeira Subject: Mapping phantom <-> non-phantom To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-ID: <475424.16703.qm@web54602.mail.re2.yahoo.com> X-Spam: no; 0.00; variants:01 variants:01 nodes:01 nodes:01 sig:01 node:01 node:01 val:01 val:01 struct:01 struct:01 ocamlyacc:01 parser:01 polymorphic:01 inline:01 Hi, Suppose you are using polymorphic variants as a phantom type to impose certain restrictions on a data structure. Is it possible in general to formulate an equivalent structure that uses only regular variants, or is the object system required for a full mapping? As an example, consider the following structure constructed using phantom types. The "Text" and "Bold" nodes may appear anywhere in a document, but the "Mref" and "See" nodes produce links, and links may not be the immediat= e parents of other links: module Phantom: sig type inline_t =3D node_t list and node_t =3D private | Text of string | Bold of inline_t | Mref of string * inline_t | See of string type 'a t val text: string -> [> `Nonlink] t val bold: [< `Link | `Nonlink] t list -> [> `Nonlink] t val mref: string -> [< `Nonlink] t list -> [> `Link] t val see: string -> [> `Link] t end =3D struct type inline_t =3D node_t list and node_t =3D | Text of string | Bold of inline_t | Mref of string * inline_t | See of string type 'a t =3D node_t let text txt =3D Text txt let bold inl =3D Bold inl let mref ref inl =3D Mref (ref, inl) let see ref =3D See ref end Though a bit contrived, the following structure expresses the same restrictions using only conventional variants: module Regular =3D struct type inline_t =3D super_node_t list and super_node_t =3D | Nonlink_node of nonlink_node_t | Link_node of link_node_t and nonlink_node_t =3D | Text of string | Bold of inline_t and link_node_t =3D | Mref of string * nonlink_node_t list | See of string end The version using PV-based phantom types doesn't require all this artifical scaffolding, and is therefore preferable in my opinion. However, the ocamlyacc grammar for a document parser will naturally be closer to the non-phantom version. My doubt is therefore if one could devise a structure using PV-based phantom types that becomes problematic to parse. Thanks in advance for your time! Kind 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