From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id ACE62D176 for ; Tue, 26 Jul 2005 03:14:43 +0200 (CEST) Received: from cenn.mc.mpls.visi.com (cenn.mc.mpls.visi.com [208.42.156.9]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j6Q1Egwl011949 for ; Tue, 26 Jul 2005 03:14:43 +0200 Received: from [192.168.42.2] (bhurt.dsl.visi.com [208.42.141.66]) by cenn.mc.mpls.visi.com (Postfix) with ESMTP id 3B3388108; Mon, 25 Jul 2005 20:14:42 -0500 (CDT) Date: Mon, 25 Jul 2005 20:15:13 -0500 (CDT) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: Stephane Glondu Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] How to do this properly with OCaml? In-Reply-To: <42E58B87.9040206@crans.org> Message-ID: References: <200507241623.13705.Stephane.Glondu@crans.org> <1122251570.9027.362.camel@localhost.localdomain> <200507242345.13152.Stephane.Glondu@crans.org> <1122291335.6766.33.camel@localhost.localdomain> <42E58B87.9040206@crans.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at nez-perce with ID 42E58E82.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 iirc:01 argued:01 integers:01 2005,:98 idx:98 idx:98 ...:98 ...:98 wrote:01 wrote:01 assert:01 ints:01 inline: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 On Mon, 25 Jul 2005, Stephane Glondu wrote: > Brian Hurt wrote: >> let get arr idx = >> if (idx < 0) || (idx > arr.len) then >> invalid_arg "get_arr" >> else >> arr.data.(idx) >> ;; > > Maybe: > > let get arr idx = > if (idx < 0) || (idx > arr.len) then > invalid_arg "get_arr" > else > match arr.data.(idx) with None -> assert false | Some a -> a > ;; > > would be better... Duh! Yeah- thinko there. That's what I meant. > Maybe storing the arr.data's length in the record would be better... Not really. Array.length is a pretty efficient routine- it gets inline to a mov, shift, and mask IIRC. > But skaller already argued that he didn't like this approach. Yep. His argument is "It's impossible to implement cleanly, except for the obvious solution, which I hate." OK, so it's not very efficient for integers. Hey, why stop there? If it's an array of chars or bools, using whole words to store individual members is inefficient! We should only store the bytes or individual bits. For anything much larger than ints, this actually isn't that inefficient. Brian