From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8SFUaHX015726 for ; Wed, 28 Sep 2011 17:30:36 +0200 X-IronPort-AV: E=Sophos;i="4.68,456,1312149600"; d="scan'208";a="122011476" Received: from macadam.inria.fr ([128.93.8.130]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/AES128-SHA; 28 Sep 2011 17:30:34 +0200 Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Damien Doligez In-Reply-To: <4E830AC3.6020405@soton.ac.uk> Date: Wed, 28 Sep 2011 17:30:33 +0200 Cc: OCaML Mailing List Content-Transfer-Encoding: 7bit Message-Id: <91C06ED2-1A8C-4F05-AEA7-ECB93A229113@inria.fr> References: <4E820844.7050705@soton.ac.uk> <2F6B5C48-88B0-4717-87FD-BD044B3D36E4@inria.fr> <4E830AC3.6020405@soton.ac.uk> To: Thomas Fischbacher X-Mailer: Apple Mail (2.1084) Subject: Re: [Caml-list] Weird GC behaviour Dear Thomas, Others have mostly answered your questions, but to be complete I want to add the following: > How come (Ftag "funny") is regarded as constant while > (Rtag (ref "funny")) is not? The difference here is that (ref "funny") is a function call. The compiler doesn't know that the "ref" function just allocates a record. > After all, strings are mutable in OCaml, > so there really is not that much of a conceptual difference between a > string and a string ref in that respect: You should rather look at the analogy between strings and arrays, but as Gabriel said, string literals are very rarely mutated in practice, so it makes more sense to have "funny" return the same string instead of allocating. > But the problem I think I have with OCaml is: there just seems to be no > way to properly express the conceptual difference between '(1 2 3 4 5) > and (list 1 2 3 4 5): All I can say above is: Ftag "Hello". You should say (Ftag (String.copy "Hello")) if you want a fresh mutable string. I wouldn't recommend appending "" or using Obj.dup (yuck!) I agree it was a mistake to make strings mutable, but we have to live with it for the time being. If you want to be perfectly safe, you can wrap all string literals with String.copy in your program. -- Damien