caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Wang <mail@philippewang.info>
To: louis.jachiet@ens.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Differences between Array and Strings
Date: Sat, 30 Apr 2011 16:06:14 +0200	[thread overview]
Message-ID: <BANLkTimQTfOShRD1S4croS--s5u5Me+FFg@mail.gmail.com> (raw)
In-Reply-To: <sympa.1304077303.17524.902@inria.fr>

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,  <louis.jachiet@ens.fr> 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 = <fun>
> # - : unit = ()
> # - : string = "2"
> # - : bool = true
> #   val l : unit -> int array = <fun>
> # - : unit = ()
> # - : int array = [|1|]
> # - : bool = false
>
> Louis Jachiet


  parent reply	other threads:[~2011-04-30 14:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-29 11:51 louis.jachiet
2011-04-29 14:36 ` David Allsopp
2011-04-30 14:06 ` Philippe Wang [this message]
     [not found] <fa.YVp+LBcZBn2VVSqyBV+/Bw0Mb/I@ifi.uio.no>
2011-04-30 11:03 ` Radu Grigore
2011-04-30 13:34   ` David Allsopp
2011-04-30 23:10     ` Martin Jambon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTimQTfOShRD1S4croS--s5u5Me+FFg@mail.gmail.com \
    --to=mail@philippewang.info \
    --cc=caml-list@inria.fr \
    --cc=louis.jachiet@ens.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).