From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8SBs7kh005681 for ; Wed, 28 Sep 2011 13:54:07 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuAAAMYJg06YToAQimdsb2JhbABCqAYUAQEBCgkNGQchgVMBAQEDAThAARALIRYPCQMCAQIBRQYOBQIBAYd0BrgihwsEh0KMEIUQEgmMCg X-IronPort-AV: E=Sophos;i="4.68,455,1312149600"; d="scan'208";a="110972144" Received: from mailgate7.iss.soton.ac.uk ([152.78.128.16]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Sep 2011 13:54:02 +0200 Received: from mailgate7.iss.soton.ac.uk (localhost.localdomain [127.0.0.1]) by mailgate7.iss.soton.ac.uk (8.13.8/8.13.4) with ESMTP id p8SBrdWr003413; Wed, 28 Sep 2011 12:53:39 +0100 Received: from UOS-MSG00010-SI.soton.ac.uk (uos-msg00010-si.soton.ac.uk [152.78.119.33]) by mailgate7.iss.soton.ac.uk (mailgate7.iss.soton.ac.uk [152.78.128.16]) envelope-from with ESMTP id n8RCrd20651446222h ret-id none; Wed, 28 Sep 2011 12:53:39 +0100 Received: from [152.78.97.98] (152.78.97.98) by smtp.soton.ac.uk (152.78.119.33) with Microsoft SMTP Server (TLS) id 8.2.213.0; Wed, 28 Sep 2011 12:53:39 +0100 Message-ID: <4E830AC3.6020405@soton.ac.uk> Date: Wed, 28 Sep 2011 12:53:39 +0100 From: Thomas Fischbacher User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) MIME-Version: 1.0 To: Damien Doligez CC: OCaML Mailing List References: <4E820844.7050705@soton.ac.uk> <2F6B5C48-88B0-4717-87FD-BD044B3D36E4@inria.fr> In-Reply-To: <2F6B5C48-88B0-4717-87FD-BD044B3D36E4@inria.fr> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-smtpf-Report: sid=n8RCrd206514462200; tid=n8RCrd20651446222h; client=relay,white,ipv6; mail=; rcpt=; nrcpt=3:0; fails=0 Received-SPF: None; receiver=mailgate7.iss.soton.ac.uk; client-ip=152.78.119.33; helo= Received-SPF: None; receiver=mailgate7.iss.soton.ac.uk; client-ip=152.78.119.33; envelope-from= X-UOS-MailScanner-Information: Please contact Serviceline@soton.ac.uk for more information X-UOS-MailScanner-ID: p8SBrdWr003413 X-UOS-MailScanner: Found to be clean X-UOS-MailScanner-From: t.fischbacher@soton.ac.uk Subject: Re: [Caml-list] Weird GC behaviour Dear Damien, >> if works >> then (get_ftag "funny",get_rtag "funny") >> else (Ftag "funny", Rtag (ref "funny")) >> in > > In this expression, you have four interesting subexpressions. Three of > them involve calling some function with "funny" as argument, and these > functions allocate values that point to the "funny" string. These values > are heap-allocated and behave as you expect. > > The fourth one is (Ftag "funny"). This is a constant expression and its > evaluation does not allocate in the heap. Since it's constant, it's > allocated once by the compiler, and every time you execute this code > it's the same value that is returned. How come (Ftag "funny") is regarded as constant while (Rtag (ref "funny")) is not? 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: http://caml.inria.fr/pub/docs/manual-ocaml/manual010.html#toc44 # type funny_str = Ftag of string;; type funny_str = Ftag of string # let s1 = Ftag "Hello";; val s1 : funny_str = Ftag "Hello" # let Ftag s = s1 in s.[0]<-'h';; - : unit = () # s1;; - : funny_str = Ftag "hello" The way I read the spec, it nowhere says that variant values that use a non-constant constructor plus a value can be treated as constant. I do see that in a sense, this may be a similar issue as the one that would arise with lisp code such as this: (defun example () (let ((text-segment-list '(1 2 3 4 5))) (nreverse text-segment-list))) Calling (example) twice gives weird behaviour, as we are destructively modifying a lisp that conceptually was constant. So, one should have used: (defun example2 () (let ((text-segment-list (list 1 2 3 4 5))) (nreverse text-segment-list))) 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". -- best regards, Thomas Fischbacher t.fischbacher@soton.ac.uk