Browse thread
[Caml-list] Stop at exception
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Mattias Waldau <mattias.waldau@a...> |
| Subject: | [Caml-list] Non-mutable strings |
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