caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Mattias Waldau" <mattias.waldau@abc.se>
To: <caml-list@inria.fr>
Subject: [Caml-list] Non-mutable strings
Date: Sat, 5 Jan 2002 12:19:45 +0100	[thread overview]
Message-ID: <AAEBJHFJOIPMMIILCEPBKEIBDGAA.mattias.waldau@abc.se> (raw)
In-Reply-To: <20020104144617.G941@pauillac.inria.fr>

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


  reply	other threads:[~2002-01-05 11:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-04  2:55 [Caml-list] Stop at exception Magesh Kannan
2002-01-04 13:46 ` Xavier Leroy
2002-01-05 11:19   ` Mattias Waldau [this message]
2002-01-05 22:01     ` [Caml-list] Non-mutable strings YAMAGATA yoriyuki
2002-01-10 17:56     ` Xavier Leroy
2002-01-10 18:25       ` [Caml-list] Float and OCaml C interface Christophe Raffalli
2002-01-12 21:12         ` David Mentre
2002-01-12 21:32           ` David Mentre
2002-01-23 15:07         ` [Caml-list] " Xavier Leroy
2002-01-23 16:02           ` David Monniaux
2002-01-10 18:41       ` [Caml-list] Non-mutable strings Patrick M Doane
2002-01-10 18:50         ` Brian Rogoff
2002-01-13 20:05           ` Nicolas George
2002-01-16 19:22       ` Mattias Waldau
2002-01-17  9:56         ` YAMAGATA yoriyuki
2002-01-17 10:19         ` Jerome Vouillon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AAEBJHFJOIPMMIILCEPBKEIBDGAA.mattias.waldau@abc.se \
    --to=mattias.waldau@abc.se \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).