Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
immutable Strings?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-03-14 (11:16)
From: Pascal Zimmer <Pascal.Zimmer@s...>
Subject: Re: [Caml-list] immutable Strings?
Jon Harrop wrote:
> On Monday 14 March 2005 10:30, Pascal Zimmer wrote:
>>The bad points:
>>- you cannot use the shortcuts s.[i] and (^) anymore (this gets the code
>>less readable especially for the first one)
>>- you have to make a copy when creating an immutable string; if you were
>>not planning to keep the original string to modify it, this copy is in
>>fact useless
> Do you not also lose the ability to do pattern matching and to use all of the 
> existing string-based functionality (e.g. the Str module)?

Yes, indeed, this is true for pattern matching. You have to replace it 
with comparisons.

For functions that use strings, you have to add a new version in your 
module, i.e. for every function
  Lib.f : ... -> string -> ...
using strings that you want to use on immutable strings, all you have to 
do is add the lines:
  val f : ... -> t -> ...
  let f = Lib.f
in module type and implementation respectively (see for example 
print_string in my previous post), and use ImmString.f instead of Lib.f.
I have to admit this can get painful if you have to use a lot of them...