On Wed, Sep 28, 2011 at 5:30 PM, Damien Doligez <[email protected]> wrote:
> You should say (Ftag (String.copy "Hello")) if you want a fresh mutable > string. I wouldn't recommend appending "" or using Obj.dup (yuck!) > > I agree it was a mistake to make strings mutable, but we have to live > with it for the time being. If you want to be perfectly safe, you can > wrap all string literals with String.copy in your program. If the world tended to be ideal at some point, I'd say it should be a compiler option, like # ocamlopt -unshared-litteral-strings (or -shared-literral-strings) Sometimes it's painful that strings are mutable, but otherwise, it would be painful too (maybe less often, I don't know). I believe that the worst is to have *both* mutable strings *and* the necessity to copy them every time mutability makes it weird. When I teach programming using OCaml, I really dislike having to explain that we have to live with this awful semantics (fortunately the language has stunning great qualities). Well, I guess this discussion has occurred thousands of times already. Sorry for that. Cheers, -- Philippe Wang [email protected] -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
