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: Loup Vaillant <loup.vaillant@g...>
Subject: Re: [Caml-list] confusion about mutable strings
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