Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] beginner needs help creating a dynamically resizable array
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-10-02 (07:00)
From: Michal Moskal <malekith@p...>
Subject: Re: [Caml-list] beginner needs help creating a dynamically resizable array
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 :: : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: