From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 18CC3BC88 for ; Sat, 5 Feb 2005 20:21:19 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j15JLIMb022133 for ; Sat, 5 Feb 2005 20:21:18 +0100 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 UAA25050 for ; Sat, 5 Feb 2005 20:21:18 +0100 (MET) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.194]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j15JLHqX022128 for ; Sat, 5 Feb 2005 20:21:17 +0100 Received: by wproxy.gmail.com with SMTP id 58so569605wri for ; Sat, 05 Feb 2005 11:21:16 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:date:from:to:cc:subject:message-id:mail-followup-to:references:mime-version:content-type:content-disposition:in-reply-to:user-agent; b=gzDncYNtPfxRTe+hJceMFdT7vobDWorHGMLYm+sHPitEHskUh5IRRxS9zH+LlgepCCbsUvA5LS0EoBEQhrFcN3PUs1wHA00qw2BW3d2EnLozkSMO0XWRd/XIiyLpsp+GJtqvfd3ngQhLkPjQScHzfzG34A8vo8Ml1SuCIwNJQ3Y= Received: by 10.54.2.63 with SMTP id 63mr326945wrb; Sat, 05 Feb 2005 11:21:16 -0800 (PST) Received: from localhost ([70.21.212.63]) by smtp.gmail.com with ESMTP id 35sm256198wra.2005.02.05.11.21.15; Sat, 05 Feb 2005 11:21:16 -0800 (PST) Date: Sat, 5 Feb 2005 14:21:13 -0500 From: Markus Mottl To: yminsky@cs.cornell.edu Cc: Caml Mailing List Subject: Re: [Caml-list] Phantom types and read-only variables Message-ID: <20050205192113.GA26897@mobile> Mail-Followup-To: yminsky@cs.cornell.edu, Caml Mailing List References: <891bd33905020508504e272acf@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <891bd33905020508504e272acf@mail.gmail.com> User-Agent: Mutt/1.5.6+20040907i X-Miltered: at nez-perce with ID 42051CAE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42051CAD.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; markus:01 mottl:01 markus:01 mottl:01 caml-list:01 read-only:01 yaron:01 minsky:01 wrote:01 compiler:01 compiler:01 val:01 val:01 mutable:01 mutable:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.5 required=5.0 tests=INFO_TLD,RCVD_BY_IP autolearn=disabled version=3.0.2 X-Spam-Level: On Sat, 05 Feb 2005, Yaron Minsky wrote: > I'm trying to use phantom types to build a "freezable" variable, where > I can create a version of the variable to which write operations can > not be applied. Here's my first attempt, which was rejected by the > compiler: [snip] > I do basically understand why the compiler rejects module N. It > basically complains that the freeze in M is not compatible with the > constraints on N. In particular: > > Values do not match: > val freeze : 'a -> 'a > is not included in > val freeze : 'a t -> ro t > > So, what's the right approach here? Hm, it seems to me that the compiler could do a better job here. Instead of writing: type 'a t = { mutable value: int } write: type v = { mutable value: int } type 'a t = v This should make the code compile. I think the compiler should be able to infer automatically that 'a isn't used on the right hand side of the record definition (i.e. that it is just a phantom type) without using the hint of a separate monomorphic record definition. I guess this feature should be trivial to add. Maybe in the next release? :-) Regards, Markus -- Markus Mottl markus.mottl@gmail.com http://www.ocaml.info