Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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'   
  end
  end;;
module ImmString : sig module String : sig val get : 'a -> 'b -> char end end
# open ImmString;;
# "foo".[3];;
hello!
- : char = 'c'


Rich.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com