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 MAA16095; Sat, 5 Jan 2002 12:20:18 +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 MAA15996 for ; Sat, 5 Jan 2002 12:20:17 +0100 (MET) Received: from mailg.telia.com (mailg.telia.com [194.22.194.26]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g05BKGT23304 for ; Sat, 5 Jan 2002 12:20:16 +0100 (MET) Received: from gateway (h175n2fls34o849.telia.com [217.208.235.175]) by mailg.telia.com (8.11.6/8.11.6) with SMTP id g05BKGh25795 for ; Sat, 5 Jan 2002 12:20:16 +0100 (CET) From: "Mattias Waldau" To: Subject: [Caml-list] Non-mutable strings Date: Sat, 5 Jan 2002 12:19:45 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) Importance: Normal In-Reply-To: <20020104144617.G941@pauillac.inria.fr> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I noted in the comments for Ocaml 3.02 - Removed re-sharing of string literals, causes too many surprises with in-place string modifications. and therefor assumes that if I have a function like let foo x = "This is a string", x ;; will foo create a new string each time foo is called? Assume that I know that no one will in-place edit the string, I could rewrite the code into the more efficient let str = "This is a string";; let foo x = str, x ;; and all calls to foo will get the same string. Is this true? If so, I wonder why not the standard strings of Ocaml are nonmutable? It works fine for languages like Visual Basic, and Visual Basic has great string performance compared to languages like C++. The only thing important to make nonmutable strings efficient is to make sure that the operation += (appending a string to an old string, where the old string probably isn't needed anymore) is efficient. (Look at a ASP/JSP-page and you will understand why :-). The reason I think nonmutable strings should be the default is that Ocaml should try to prevent hard-to-find bugs, and allowing in-change editing of strings is a typical case. (I can definitily live without mutable strings, but mutable fields, ref, and arrays I cannot live without.) /mattias P.s. Could phantom types be used to close (=make const) strings, arrays, and maybe even mutable/ref, so that clients are not allowed to change them? ------------------- 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