From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 873FBBB83 for ; Fri, 26 May 2006 08:51:45 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k4Q6piv0029878 for ; Fri, 26 May 2006 08:51:45 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA23322 for ; Fri, 26 May 2006 08:51:44 +0200 (MET DST) Received: from smtp1-g19.free.fr (smtp1-g19.free.fr [212.27.42.27]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k4Q6pihs029875 for ; Fri, 26 May 2006 08:51:44 +0200 Received: from [192.168.0.2] (rke75-3-82-229-183-156.fbx.proxad.net [82.229.183.156]) by smtp1-g19.free.fr (Postfix) with ESMTP id 0501F9AAA7; Fri, 26 May 2006 08:51:43 +0200 (CEST) Message-ID: <4476A57F.8050902@inria.fr> Date: Fri, 26 May 2006 08:51:43 +0200 From: Alain Frisch User-Agent: Thunderbird 1.5.0.2 (X11/20060421) MIME-Version: 1.0 To: Brian Hurt Cc: caml-list@inria.fr Subject: Re: [Caml-list] Re: immutable strings (Re: Array 4 MB size limit) References: <20060515141230.ajyupn2z28k0484s@horde.akalin.cx> <446D5E4A.8060005@akalin.cx> <20060519162844.GA32550@osiris.uid0.sk> <200605192226.34917.jon@ffconsultancy.com> <20060520211117.GA2670@first.in-berlin.de> In-Reply-To: X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4476A580.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4476A580.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; frisch:01 frisch:01 ocaml:01 ocaml's:01 foo:01 foo:01 ocaml:01 eliminates:98 wrote:01 constants:01 caml-list:01 expression:01 expression:01 immutable:01 strings:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Brian Hurt wrote: > Note that this also eliminates an inefficiency of ocaml. When you use a > constant string, it has to allocate a new string for you. Consider > Ocaml's response to the expression: > > "foo" == "foo";; > > The reason ocaml returns false in the above expression is that when you > give a constant string in an expression, Ocaml first has to make a copy > of that string (in case you modify it), and then it returns the copy. This is not true. The two strings above are physically different because the two constants appear at different location of the source. The expression let f () = "foo" in f () == f () evaluates to true. The block for "foo" is allocated only once; the string is not copied not each time the body of f is evaluated. As a consequence, let f () = "foo" in (f ()).[0] <- 'F'; f () returns "Foo". -- Alain