From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA20464; Thu, 2 Oct 2003 09:00:17 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA18128 for ; Thu, 2 Oct 2003 09:00:16 +0200 (MET DST) Received: from ep09.kernel.pl (ep09.kernel.pl [212.87.11.162]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h9270FH08548 for ; Thu, 2 Oct 2003 09:00:15 +0200 (MET DST) Received: (qmail 3135 invoked by uid 566); 2 Oct 2003 07:00:08 -0000 Date: Thu, 2 Oct 2003 08:58:15 +0200 From: Michal Moskal To: Ram Bhamidipaty Cc: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] beginner needs help creating a dynamically resizable array Message-ID: <20031002065815.GA3921@roke.freak> Mail-Followup-To: Ram Bhamidipaty , caml-list@pauillac.inria.fr References: <16251.48822.166307.867159@oak.ramandgita.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <16251.48822.166307.867159@oak.ramandgita.com> User-Agent: Mutt/1.4.1i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; michal:01 moskal:01 malekith:01 pld-linux:01 caml-list:01 dynamically:01 dynamically:01 resize:01 trickery:01 michal:01 moskal:01 malekith:01 kernel:01 ocaml:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, Oct 01, 2003 at 10:59:18PM -0700, Ram Bhamidipaty wrote: > I am trying to create a dynamically resizable array. [...] > let resize dyn_array_ref new_size = [...] > The problem I am running into is that I don't know how to create a new > larger array of the same time as the original array. The only two > choices that I can think of are: 1. Somehow store the type of the > array in the record or 2. Somehow get the array element type from the > "buf" array in the record. > > Unfortunately I have no idea about how to do either 1 or 2. You can fill your array with *value* buf.{0}. You don't need its type. This will present some odds for the GC, but if it's for educational purposes then it's OK. The other way is Obj.magic trickery... > I know there is atleast one package/module that provides this > functionality. But I don't want to use someone elses code - I am > trying to learn OCaml and I think this would be a good thing to do > with my own code. ...and for this reason I personally don't think it's best example to learn OCaml on. -- : Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv : When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners