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: | Patrick M Doane <patrick@w...> |
| Subject: | Re: [Caml-list] Non-mutable strings |
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