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 TAA22021; Thu, 10 Jan 2002 19:41:23 +0100 (MET) 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 TAA21925 for ; Thu, 10 Jan 2002 19:41:22 +0100 (MET) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g0AIfLL06921; Thu, 10 Jan 2002 19:41:21 +0100 (MET) Received: from localhost (patrick@localhost) by fledge.watson.org (8.11.6/8.11.5) with ESMTP id g0AIfGD64538; Thu, 10 Jan 2002 13:41:16 -0500 (EST) (envelope-from patrick@watson.org) Date: Thu, 10 Jan 2002 13:41:15 -0500 (EST) From: Patrick M Doane To: Xavier Leroy cc: Mattias Waldau , Subject: Re: [Caml-list] Non-mutable strings In-Reply-To: <20020110185619.A20606@pauillac.inria.fr> Message-ID: <20020110133809.N63176-100000@fledge.watson.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 10 Jan 2002, Xavier Leroy wrote: > If we were to start again from scratch, I'd consider immutable strings > seriously. Having mutable strings is handy when they are used as > character buffers, e.g. by low-level I/O functions. But I agree there > are advantages to distinguish (immutable) strings and (mutable) > character buffers. In some situations, I've been able to simply make an immutable replacement for the String module: module String = struct let length = String.length let get = String.get let create = String.create let copy = String.copy let sub = String.sub (* .. *) end # let s = "foo";; val s : string = "foo" # s.[0];; - : char = 'f' # s.[0] <- 'g';; Toplevel input: # s.[0] <- 'g';; ^^^^^^^^^^^^ Unbound value String.set This only works if all the strings in the current context are immutable though. Patrick ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr