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.1 required=5.0 tests=AWL 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 AD9B6BBAF for ; Mon, 6 Apr 2009 11:19:59 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aj0DAFtm2UnCpx6wgWdsb2JhbACWJgEBFiKyB4JIgUcG X-IronPort-AV: E=Sophos;i="4.39,329,1235948400"; d="scan'208";a="25714179" Received: from smtpmin.univ-orleans.fr (HELO min.univ-orleans.fr) ([194.167.30.176]) by mail3-smtp-sop.national.inria.fr with ESMTP; 06 Apr 2009 11:19:48 +0200 Received: from smtps.univ-orleans.fr (localhost [127.0.0.1]) by min.univ-orleans.fr (Postfix) with ESMTP id 7052812B59C; Mon, 6 Apr 2009 11:19:46 +0200 (CEST) Received: from [192.168.0.12] (ras75-4-82-235-58-110.fbx.proxad.net [82.235.58.110]) by smtps.univ-orleans.fr (Postfix) with ESMTP id 5AB1E36E64; Mon, 6 Apr 2009 11:19:47 +0200 (CEST) Subject: Re: Strings From: David Rajchenbach-Teller To: Zheng Li Cc: Goswin von Brederlow , Daniel Buenzli , OCaml List In-Reply-To: <49D8828C.40402@users.sourceforge.net> References: <200904031256.33357.jon@ffconsultancy.com> <200904031546.14071.jon@ffconsultancy.com> <49D63EE6.2020407@ens-lyon.org> <8697F924-0485-4E00-81DF-9BCF74D872EA@erratique.ch> <87prftifa3.fsf@frosties.localdomain> <1238836234.6250.6.camel@Blefuscu> <49D8828C.40402@users.sourceforge.net> Content-Type: text/plain Date: Mon, 06 Apr 2009 11:20:23 +0200 Message-Id: <1239009623.6058.28.camel@Blefuscu> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 0200,:01 abstraction:01 read-only:01 val:01 compiler:01 read-only:01 stdout:01 cheers:01 2009:98 wrote:01 readable:01 compile:01 immutable:01 strings:01 On Sun, 2009-04-05 at 12:06 +0200, Zheng Li wrote: > With phantom type alone, the abstraction can still leak. Ok, it's actually not *immutable* strings but *read-only* strings. The objective is to be able to distribute a text and make sure that the client won't be able to modify it. The original owner can still decide to enter "mutable-land" if they need it. > > ---- > # let ro_s = ro"asdf";; > val ro_s : [ `Read ] Batteries.String.Cap.t = ro"asdf" > # (to_string ro_s).[3] <- 'z';; > .... > ---- > > however, with no covariants defined in batteries' String.Cap.t type > (why?), the second example won't compile. That's by design: [to_string] is the identity operation and it only applies to strings for which you have both read and write capabilities. If you wish to do what I believe you have in mind, you need to first [copy] the string. > The compiler simply doesn't > allow me to print out a read-only string, nor does it allow many > reasonable things like <> etc. Er, how can you "not print out a read-only string"? And for your [join] problem, well, works for me (as soon as you remember that it takes as second argument a *list* of readable strings). # print stdout (join ro";" [ro"1"; ro"2"; ro"3"]);; 1;2;3- : unit Cheers, David