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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 757D0D169 for ; Sun, 24 Jul 2005 23:55:35 +0200 (CEST) Received: from ash25e.internode.on.net (ash25e.internode.on.net [203.16.214.182]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j6OLtXUq002427 for ; Sun, 24 Jul 2005 23:55:34 +0200 Received: from rosella (ppp9-20.lns1.syd3.internode.on.net [59.167.9.20]) by ash25e.internode.on.net (8.12.9/8.12.6) with ESMTP id j6OLtSjn044490; Mon, 25 Jul 2005 07:25:28 +0930 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Re: [Caml-list] How to do this properly with OCaml? From: skaller To: Stephane Glondu Cc: caml-list@yquem.inria.fr In-Reply-To: <200507241408.29014.Stephane.Glondu@crans.org> References: <1122236998.9027.163.camel@localhost.localdomain> <1122238196.9027.171.camel@localhost.localdomain> <200507241408.29014.Stephane.Glondu@crans.org> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-CGs6iZ+jd1gRoa2qe40w" Date: Mon, 25 Jul 2005 07:55:29 +1000 Message-Id: <1122242129.9027.229.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 X-Miltered: at concorde with ID 42E40E55.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 buffer:01 buffer:01 val:01 initialise:01 mutable:01 ...:98 wrote:01 sourceforge:01 sourceforge:01 arbitrary:01 assert:01 typing:01 constructor:01 X-Attachments: type="application/pgp-signature" name="signature.asc" 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 --=-CGs6iZ+jd1gRoa2qe40w Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Sun, 2005-07-24 at 14:08 -0700, Stephane Glondu wrote: > BTW, I was talking about 'a array option, not 'a option array. You can us= e=20 > (mostly of) the implementation of Buffer, hence have the same=20 > efficiency... I don't understand your point about "efficiency". If you=20 > think that the Buffer implementation is not efficient, I may agree with=20 > you, but this is an algorithmic issue, not a typing issue.=20 Observe the constructor: let create n =3D let n =3D if n < 1 then 1 else n in let n =3D if n > Sys.max_string_length then Sys.max_string_length else n in let s =3D String.create n in {buffer =3D s; position =3D 0; length =3D n; initial_buffer =3D s} creates an *uninitialised* string of length n: "val create : int -> string String.create n returns a fresh string of length n. The string initially contains arbitrary characters." If you have to initialise the store, it is expensive, and if you have to provide a dummy value it is hard to use. If you used a 'a array option, and=20 assert (match Some a -> Array.length a > 0 | None -> true) then you can use the first value of the array as the dummy value for the rest of the array, and avoid Obj.magic -- however this is very inefficient, since the dummy would have to be changed in many places whenever the first entry in the array changed (and that isn't just a store -- there is a write-barrier to think about .. :) That won't happen in Buffer because you can't modify it, but it must be allowed in more general variable length mutable array. --=20 John Skaller --=-CGs6iZ+jd1gRoa2qe40w Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQBC5A5PsRp8/9aGVGsRAhdqAKCM8zv7UXPnoxqKEYrGQQERPf5QBQCgnOsK UXo2+9eRUUSDkM4uK6rD3Lc= =rAYF -----END PGP SIGNATURE----- --=-CGs6iZ+jd1gRoa2qe40w--