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 5B65ED176 for ; Tue, 26 Jul 2005 03:03:19 +0200 (CEST) Received: from salzburg.ucdavis.edu (salzburg.ucdavis.edu [169.237.104.162]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j6Q13GbK006074 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Tue, 26 Jul 2005 03:03:18 +0200 Received: from [169.237.7.95] (puck.cs.ucdavis.edu [169.237.7.95]) by salzburg.ucdavis.edu (8.13.3/8.13.1/it-defang-5.4.0) with ESMTP id j6Q13DnY002085; Mon, 25 Jul 2005 18:03:13 -0700 (PDT) Message-ID: <42E58B87.9040206@crans.org> Date: Mon, 25 Jul 2005 18:01:59 -0700 From: Stephane Glondu User-Agent: Debian Thunderbird 1.0.2 (X11/20050331) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Brian Hurt Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] How to do this properly with OCaml? 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> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.49 on 169.237.104.162 X-Miltered: at concorde with ID 42E58BD5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 blit:01 argued:01 idx:98 idx:98 ...:98 ...:98 wrote:01 abstract:01 assert:01 data:02 data:02 append:02 match:02 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: > 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... > let append arr x = (* add x to the end of arr *) > if (arr.len == (Array.length arr.data)) then > begin > let newarr = Array.make (2*arr.len) None in > Array.blit arr.data 0 newarr 0 arr.len; > arr.data <- newarr; > end; > arr.data.(arr.len) <- Some(x); > arr.len <- arr.len + 1; > () > ;; Maybe storing the arr.data's length in the record would be better... Of course, all this would be wrapped in a module so that 'a t is an abstract type. But skaller already argued that he didn't like this approach. -- Stephane Glondu.