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 (12:57)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] immutable Strings?
On Mon, Mar 14, 2005 at 11:30:57AM +0100, Pascal Zimmer wrote:
> - you cannot use the shortcuts s.[i] and (^) anymore (this gets the code 
> less readable especially for the first one)

You can get the s.[i] shortcut by naming your module
'ImmString.String' (using a nested module in other words) and using
'open ImmString'.  However this has the further problem that you then
can no longer use mutable strings :-( although perhaps Oliver has
forsworn use of mutable strings, so this is an acceptable compromise
for him.

# module ImmString = struct
  module String = struct
  let get s i = prerr_endline "hello!"; 'c'   
module ImmString : sig module String : sig val get : 'a -> 'b -> char end end
# open ImmString;;
# "foo".[3];;
- : char = 'c'


Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology -
Team Notepad - intranets and extranets for business -