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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 7E50DBBAF for ; Fri, 27 Jun 2008 22:35:59 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As0AAEnsZEjOvjGxfGdsb2JhbACSZQEBCwUCBgcRA58p X-IronPort-AV: E=Sophos;i="4.27,716,1204498800"; d="scan'208";a="26797495" Received: from web54607.mail.re2.yahoo.com ([206.190.49.177]) by mail4-smtp-sop.national.inria.fr with SMTP; 27 Jun 2008 22:35:58 +0200 Received: (qmail 73484 invoked by uid 60001); 27 Jun 2008 20:35:57 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-Mailer:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=RYNUiBaBsFoJFJQEdVFuh5HbwWiOU+qkWCpLnhAIkPOPBJ/On4BLRp5Io5dP5ahDeo7ElwDvsKLkB2ljWkXj942ETmELq857vW3NwzRbDMR56YeLRrTswFpTTdY+hTxU+Z1jq8Oj5j/o+yQx83ZPj5q4iOi0ShvgbXytpn7AZwk=; Received: from [212.13.63.128] by web54607.mail.re2.yahoo.com via HTTP; Fri, 27 Jun 2008 13:35:57 PDT X-Mailer: YahooMailWebService/0.7.199 Date: Fri, 27 Jun 2008 13:35:57 -0700 (PDT) From: Dario Teixeira Subject: Re: [Caml-list] Phantom types: transparency vs rogue unification To: caml-list@yquem.inria.fr In-Reply-To: <720820.32869.qm@web54603.mail.re2.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-ID: <674022.73253.qm@web54607.mail.re2.yahoo.com> X-Spam: no; 0.00; unification:01 functor:01 non-trivial:01 node:01 node:01 opaqueness:01 sig:01 val:01 val:01 struct:01 parser:01 parser:01 sig:01 subset:01 struct:01 > I may have spoken too soon about the functor solving the > problem. In fact, > in a non-trivial example the problem is merely shifted to a > different place. Hi, Just to let you know that I have found an embarrassingly simple workaround: the Document module can just provide node_of_complex and node_of_basic functions to overcome the opaqueness of Document.t. I haven't found (yet) any major disadvantages to this solution, so I reckon the problem can be solved this way (code below). Thanks again for your attention, Dario Teixeira ___________________________________________________________________________ (************************************************************************) (* Document.=09=09=09=09=09=09=09=09*) (************************************************************************) module type DOCUMENT =3D sig =09type inline_t =3D node_t list =09 and node_t =3D =09=09private =09=09| Text of string =09=09| Bold of inline_t =09=09| Italic of inline_t =09type 'a t =09val node_of_complex: [< `Basic | `Complex] t -> node_t =09val node_of_basic: [< `Basic] t -> node_t =09val text: string -> [> `Basic] t =09val bold: 'a t list -> 'a t =09val italic: [< `Basic | `Complex] t list -> [> `Complex] t end module Document : DOCUMENT =3D struct =09type inline_t =3D node_t list =09 and node_t =3D =09=09| Text of string =09=09| Bold of inline_t =09=09| Italic of inline_t =09type 'a t =3D node_t =09let node_of_complex node =3D node =09let node_of_basic node =3D node =09let text str =3D Text str =09let bold inl =3D Bold inl =09let italic inl =3D Italic inl end (************************************************************************) (* Document_parser.=09=09=09=09=09=09=09*) (************************************************************************) module Document_parser: sig =09exception Invalid_subset =09val parse_complex: string -> [> `Basic | `Complex] Document.t =09val parse_basic: string -> [> `Basic] Document.t end =3D struct =09open Document =09exception Invalid_subset =09let parse_complex =3D function =09=09| "complex" -> italic [bold [text "ola"]] =09=09| _ -> bold [text "ola"] =09let complex_to_basic node =3D =09=09let rec complex_to_basic_aux =3D function =09=09=09| Text str -> text str =09=09=09| Bold inl -> bold (List.map complex_to_basic_aux inl) =09=09=09| Italic inl -> raise Invalid_subset =09=09in complex_to_basic_aux (node_of_complex node) =09let parse_basic str =3D complex_to_basic (parse_complex str) end (************************************************************************) (* top-level.=09=09=09=09=09=09=09=09*) (************************************************************************) open Document open Document_parser let foo =3D bold [text "foo"];; let bar =3D italic [text "bar"];; let a =3D parse_complex "complex";; let b =3D parse_complex "basic";; let c =3D parse_basic "basic";; let d =3D parse_basic "complex";; (* Raises exception *) ___________________________________________________________________________ =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