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 59CA7BBAF for ; Wed, 25 Jun 2008 16:26:32 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiwBAODxYUjOvjGxfGdsb2JhbACSVQEBCwUCBgcRA59G X-IronPort-AV: E=Sophos;i="4.27,702,1204498800"; d="scan'208";a="14514280" Received: from web54607.mail.re2.yahoo.com ([206.190.49.177]) by mail3-smtp-sop.national.inria.fr with SMTP; 25 Jun 2008 16:26:31 +0200 Received: (qmail 4069 invoked by uid 60001); 25 Jun 2008 14:26:30 -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=Ilcj61eNWB8ex9BDoHjmfDRUTwXcMM6xJryMAUCM1mQ8gtrdsVTBJba61jROK2emlRn0ZsCaCoC/1gQrQEkecoFCk5je1b60yRgC1759xuC1UxrkUJC/D6vrnEGO43uXEVDOpQfTGcPjOMI4hgiBkTK5HM0359GzRs4/qSdFllM=; Received: from [212.13.62.47] by web54607.mail.re2.yahoo.com via HTTP; Wed, 25 Jun 2008 07:26:30 PDT X-Mailer: YahooMailWebService/0.7.199 Date: Wed, 25 Jun 2008 07:26:30 -0700 (PDT) From: Dario Teixeira Subject: Phantom types: transparency vs rogue unification To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-ID: <767974.3892.qm@web54607.mail.re2.yahoo.com> X-Spam: no; 0.00; unification:01 module's:01 unification:01 sig:01 val:01 val:01 struct:01 foo:01 sig:01 struct:01 foo:01 cheers:01 1.0:98 2.0:98 1.0:98 Hi, I've been experimenting with phantom types since I've read Richard Jones' excellent intro to the subject [1]. I've now come across a tricky problem, however. Essentially, I need to reconcile two seemingly incompatible goals= : making a module's phantom type opaque to avoid the "rogue unification" issu= e, and making it transparent so that external modules can produce values of that type. So, suppose I have a "Stringies" module, which uses a phantom string to parametrise floats. Because the phantom type is opaque, the rogue unificat= ion is prevented in the last line: _______________________________________________________________ module Stringies: sig type 'a t val make: float -> string t val add: string t -> string t -> string t end =3D struct type 'a t =3D float let make x =3D x let add a b =3D a +. b end open Stringies let foo =3D add (make 1.0) (make 2.0);; let bar =3D add (make 1.0) 2.0;; (* Error! *) _______________________________________________________________ But suppose you wish to create an external module with a function to parse strings into Stringies.t. The phantom must become visible, but that allows for rogue unification to take place: _______________________________________________________________ module Stringies: sig type 'a t =3D float val make: float -> string t val add: string t -> string t -> string t end =3D struct type 'a t =3D float let make x =3D x let add a b =3D a +. b end module Stringies_IO: sig val parse: string -> string Stringies.t end =3D struct let parse =3D float_of_string end open Stringies let foo =3D add (make 1.0) (Stringies_IO.parse "2.0");; let bar =3D add (make 1.0) 2.0;; (* Rogue unification! *) _______________________________________________________________ How would you go about solving this problem? Thanks in advance! cheers, Dario Teixeira [1] http://camltastic.blogspot.com/2008/05/phantom-types.html =0A=0A=0A __________________________________________________________= =0ASent from Yahoo! Mail.=0AA Smarter Email http://uk.docs.yahoo.com/nowyou= can.html