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 1BA0FBC48 for ; Mon, 14 Mar 2005 12:16:05 +0100 (CET) Received: from daimi.au.dk (daimi.au.dk [130.225.16.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2EBG4PO018196 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 14 Mar 2005 12:16:04 +0100 Received: from [10.11.41.210] (arwen [10.11.41.210]) (authenticated bits=0) by daimi.au.dk (8.12.11/8.12.11) with ESMTP id j2EBG07W004295; Mon, 14 Mar 2005 12:16:00 +0100 Message-ID: <4235726F.3020403@sophia.inria.fr> Date: Mon, 14 Mar 2005 12:15:59 +0100 From: Pascal Zimmer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020 X-Accept-Language: fr, fr-fr, en MIME-Version: 1.0 To: Jon Harrop Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] immutable Strings? References: <20050312205011.GA2244@first.in-berlin.de> <423567E1.1030909@sophia.inria.fr> <200503141041.34682.jon@ffconsultancy.com> In-Reply-To: <200503141041.34682.jon@ffconsultancy.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-DAIMI-Spam-Score: 0 () X-Scanned-By: MIMEDefang 2.44 X-Miltered: at nez-perce with ID 42357274.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 lib:01 val:01 lib:01 ...:98 ...:98 wrote:01 wrote:01 strings:01 strings:01 functions:01 immutable:01 immutable:01 readable:02 sophia:03 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=none autolearn=disabled version=3.0.2 X-Spam-Level: Jon Harrop wrote: > On Monday 14 March 2005 10:30, Pascal Zimmer wrote: > >>The bad points: >>- you cannot use the shortcuts s.[i] and (^) anymore (this gets the code >>less readable especially for the first one) >>- you have to make a copy when creating an immutable string; if you were >>not planning to keep the original string to modify it, this copy is in >>fact useless > > > Do you not also lose the ability to do pattern matching and to use all of the > existing string-based functionality (e.g. the Str module)? > Yes, indeed, this is true for pattern matching. You have to replace it with comparisons. For functions that use strings, you have to add a new version in your module, i.e. for every function Lib.f : ... -> string -> ... using strings that you want to use on immutable strings, all you have to do is add the lines: val f : ... -> t -> ... let f = Lib.f in module type and implementation respectively (see for example print_string in my previous post), and use ImmString.f instead of Lib.f. I have to admit this can get painful if you have to use a lot of them... Pascal