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 991C3BC88 for ; Sat, 5 Feb 2005 18:24:44 +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 j15HOihI011704 for ; Sat, 5 Feb 2005 18:24:44 +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 SAA21428 for ; Sat, 5 Feb 2005 18:24:43 +0100 (MET) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.193]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j15HOg1p011701 for ; Sat, 5 Feb 2005 18:24:43 +0100 Received: by wproxy.gmail.com with SMTP id 58so561724wri for ; Sat, 05 Feb 2005 09:24:42 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=npDk0RlHIi49dDmoX5bGZxwXVqblxUHYpJaExLSj7bUHfZXvqbn5hh5lhCsMS4YbI4cDTQaA5PkjErAPdW0kC4VCdpAftIneCsKUk6wPmiB6CVMK0kF57vcBDQJtWEx1IuI9IracAJGDoWxQ+3bagNDgpGJk8Pnc7rGR8iFR3Bk= Received: by 10.54.14.21 with SMTP id 21mr202423wrn; Sat, 05 Feb 2005 09:24:42 -0800 (PST) Received: by 10.54.2.70 with HTTP; Sat, 5 Feb 2005 09:24:41 -0800 (PST) Message-ID: <891bd33905020509243edf074d@mail.gmail.com> Date: Sat, 5 Feb 2005 12:24:41 -0500 From: Yaron Minsky Reply-To: yminsky@cs.cornell.edu To: Caml Mailing List Subject: Re: Phantom types and read-only variables In-Reply-To: <891bd33905020508504e272acf@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <891bd33905020508504e272acf@mail.gmail.com> X-Miltered: at nez-perce with ID 4205015C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4205015A.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; yaron:01 minsky:01 yminsky:01 read-only:01 yaron:01 minsky:01 yminsky:01 wrote:01 compiler:01 struct:01 mutable:01 sig:01 val:01 val:01 compiler:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.2 X-Spam-Level: One addendum. this can clearly be done with Obj.magic, but I'm wondering if there's any safe alternative. y On Sat, 5 Feb 2005 11:50:43 -0500, 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: > > type ro = Readonly > type rw = Readwrite > > module M = > struct > type 'a t = { mutable value: int } > > let create i = { value = i } > let freeze t = t > let read x = x.value > let write x i = > x.value <- i > end > > module N = > (M : sig > type 'a t > val create : int -> rw t > val freeze : 'a t -> ro t > val read : 'a t -> int > val write : rw t -> int -> unit > end) > > 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? > > y >