Version française
Home     About     Download     Resources     Contact us    
Browse thread
confusion about mutable strings
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Ralph Douglass <ralph@g...>
Subject: Re: [Caml-list] confusion about mutable strings
Sorry, I was indeed informed today by someone at work that it was talked
about a week or two ago.  There is so much going on on the list that I just
missed it.  And now I added noise myself.  Sigh.

Thanks,

Ralph

On 2/11/08, Loup Vaillant <loup.vaillant@gmail.com> wrote:
>
> 2008/2/11, Ralph Douglass <ralph@grayskies.net>:
> >
> > Observe the following:
> >
> > # let foo () =
> >   let bar = [|'a';'b';'c'|] in
> >   Array.iter (Printf.printf "%c") bar;
> >   bar.(0) <- 'd';
> >   bar;;
> > val foo : unit -> char array = <fun>
> >  # foo ();;
> > abc- : char array = [|'d'; 'b'; 'c'|]
> > # foo ();;
> > abc- : char array = [|'d'; 'b'; 'c'|]
> >
> > Why does OCaml treat these two examples in such a different manner?  Is
> > there a reason why strings are magically special in this way?
>
> C strings are usually "magically special" in exactly the same way. It
> has been talked about in another thread (dunno how to look for it).
> Basically, this is a design choice meant for better performance.
>
> Loup
>



-- 
Ralph