From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA09410; Wed, 25 Aug 2004 23:03:36 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA09347 for ; Wed, 25 Aug 2004 23:03:34 +0200 (MET DST) Received: from mail3.speakeasy.net (mail3.speakeasy.net [216.254.0.203]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i7PL3W6B029352 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 25 Aug 2004 23:03:34 +0200 Received: (qmail 29674 invoked from network); 25 Aug 2004 21:03:30 -0000 Received: from shell2.speakeasy.net ([69.17.110.71]) (envelope-sender ) by mail3.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 25 Aug 2004 21:03:30 -0000 Date: Wed, 25 Aug 2004 14:03:30 -0700 (PDT) From: brogoff To: Jon Harrop cc: caml-list@inria.fr Subject: Re: [Caml-list] Phantom types In-Reply-To: <200408231049.59342.jon@jdh30.plus.com> Message-ID: References: <410B5EBD.6060800@cgorski.org> <200407311444.56864.jon@jdh30.plus.com> <20040731163143.GB15775@fichte.ai.univie.ac.at> <200408231049.59342.jon@jdh30.plus.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 412CFEA4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 brogoff:01 caml-list:01 2004:99 markus':01 bug:01 checker:01 monomorphic:01 abstr:01 ocaml:01 speakeasy:01 variants:01 phantom:01 phantom:01 sig:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 23 Aug 2004, Jon Harrop wrote: > On Saturday 31 July 2004 17:31, Markus Mottl wrote: > > module type PHANTOM_INT = sig > > type 'p t > > ... > > Right, I've had a bit more of a chance to play with phantom types now, and I'm > quite confused. :-) > > As far as I can tell, there were a few errors in Markus' original (I may well > be wrong, of course), so here is my altered version: [...snip...] Yes, those look like errors, and your fixes look good. > So I've changed the types to be [ `Even ] instead of [> `Even ] and the "make" > functions to be "int -> ...". This appear to work as desired: that's what you want in this example. > Now, there are some subtle peculiarities of these which I don't understand. > Firstly, the type checking of the phantom types only seems to work if the > type is made abstract in the module signature. I can't think why this should > make a difference though. For example, changing "type 'p t" to "type 'p t = > int" in "PhantomInt : sig" then allows: > > # PhantomInt.add_even_even i j;; > - : [ `Even ] PhantomInt.t = 5 > > which is clearly undesirable. This looks like a bug in the OCaml type checker. It also occurs if you replace the polymorphic variants with type even = Even and odd = Odd. It remains if you replace the phantom type int by int64 or even int array, but goes away when you replace the phantom type by type 'p t = { data = int } or type 'p t = Int int. So the built in types appear to be being treated differently. > Secondly, specifying the types as Markus did (e.g. [> `Even]), which I think > should have been correct, leads to some kind of monomorphic type: > > # PhantomInt.add_even_odd i j;; > - : _[> `Odd ] PhantomInt.t = A [> or [< means there's an implicit type variable. -- Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners