From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p3UE6LW6030591 for ; Sat, 30 Apr 2011 16:06:21 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkcDAG0WvE3RVdg2i2dsb2JhbACYUY0+CBQBAQEKCwsHEgYhpzqNJoQgiRIBAQMGhXoEiTCFSYo6O4Ejggw X-IronPort-AV: E=Sophos;i="4.64,292,1301868000"; d="scan'208";a="82066500" Received: from mail-qw0-f54.google.com ([209.85.216.54]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 30 Apr 2011 16:06:15 +0200 Received: by qwc9 with SMTP id 9so3657261qwc.27 for ; Sat, 30 Apr 2011 07:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Ok88sZv+VmAar/ckqKEItBi9+PWUKQ5lRHepKejVCKI=; b=Li7QFSufs3IdUa07k2T0kwOWRRJYtf6UIoNtcQiXwQEX8KvWpx9u0lV1qq4dQFSFLS elxtwIqDkb9+7PDh0kJHvcOeoZ4mCf7Szlzj/dDTq+hZHzsZoAIzNSfkS9zOcRakURF/ j+XoCJY8PfNfsQ0jzp/wSm2t+DOZDT/0wP6cM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=tQ1S1+yr8RtSrDnAz7y/3tx2DI7oAa7V0ZuFZFtzTC6RBY9L+CWBhNwkOfVNJfASFY P+aQU9VihCYmACy2mqUKnp//cGJThS5WZxwHiJzD9En6GrpsFJ3hDlPOTamxJEyCY8AW EPKeUsNOShmWjnRcDOQKdLqDsABYckE/HVygo= MIME-Version: 1.0 Received: by 10.229.69.213 with SMTP id a21mr4659578qcj.222.1304172374607; Sat, 30 Apr 2011 07:06:14 -0700 (PDT) Sender: philippe.wang.lists@gmail.com Received: by 10.229.8.197 with HTTP; Sat, 30 Apr 2011 07:06:14 -0700 (PDT) In-Reply-To: References: Date: Sat, 30 Apr 2011 16:06:14 +0200 X-Google-Sender-Auth: OkfBfaQ1w5zDsHE1EMHsAVDHiaQ Message-ID: From: Philippe Wang To: louis.jachiet@ens.fr Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p3UE6LW6030591 Subject: Re: [Caml-list] Differences between Array and Strings It's a weird feature of OCaml... Anyway, if you want to allocate a string, you should write let l () = String.copy "1" instead of let l () = "1" -- Philippe Wang mail@philippewang.info On Fri, Apr 29, 2011 at 1:51 PM, wrote: > Hi, I'am failing to understand the behavior of the code below. Why the string > is not regenerated ? Why strings and array have not the same behavior ? > >> let l () = "1" ;; >> (l ()).[0] <- '2';; >> l ();; >> l()==l();; > >> let l () = [|1|] ;; >> (l ()).(0) <- 2;; >> l ();; >> l() == l() ;; > > # val l : unit -> string = > # - : unit = () > # - : string = "2" > # - : bool = true > #   val l : unit -> int array = > # - : unit = () > # - : int array = [|1|] > # - : bool = false > > Louis Jachiet