skaller wrote:
On Mon, 2007-10-08 at 18:04 +0200, Gerd Stolpmann wrote:

  
I heard that OCaml is particularly slow (and probably
memory-inefficient) when it comes to string manipulation.
      
No, this is nonsense. Of course, you can slow everything down by using
strings in an inappropriate way, like

let rec concat_list l =
  match l with
    [] -> ""
  | s :: l' -> s ^ concat_list l'
    

Now Gerd, I would not call the claim nonsense. If you can't
use a data structure in a natural way, I'd say the claim indeed
has some weight.

The example above is ugly because it isn't tail recursive.
If you consider an imperative loop to concat the strings
in an array

	let s = ref "" in
	for i = 0 to Array.length a do
		s := !s ^ a.[i]
	done;

then Ocaml is likely to do this slowly. C++ on the other
hand will probably do this faster, especially if you reserve
enough storage first.
  

And if you don't, and thus have to repeatedly allocate more memory, C++ is likely going to be slower than Ocaml (poor allocation performance).  In fact, I'm willing to bet you can get near C++ speed by doing things in the C++ way- allocate the string once (with enough space), and then use String.blit to fill it in.

That said, there are better implementations of strings for Ocaml.  So what?  Ocaml isn't a string processing language.  Yeah, there are things which are probably better done in Perl/Python/Ruby.  A language doesn't have to be the perfect language for all purposes in order to be a good language- in fact, in my experience languages that try to be everything to everybody end up being useless for all purposes (C++ being example #1 here).

Brian