caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] beginner needs help creating a dynamically resizable array
@ 2003-10-02  5:59 Ram Bhamidipaty
  2003-10-02  6:58 ` Michal Moskal
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ram Bhamidipaty @ 2003-10-02  5:59 UTC (permalink / raw)
  To: caml-list

I am trying to create a dynamically resizable array. So far this is what I have:

type 'a darray = {
    mutable size_of_buf : int;
    mutable num_in_buf : int;
    mutable buf : 'a array;
  }
;;

let create t = { size_of_buf=20; num_in_buf=0; buf = Array.make 20 t; }
;;

I want to create a function that can resize this array. I want the
function to look something like this:

let resize dyn_array_ref new_size =
  
;;

The function resize should table a reference to a darray record, and
an int that specifies the new desired size of the array. There should
be no return value.

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.

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.

Any help will be appreciated.
-Ram

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] beginner needs help creating a dynamically resizable array
  2003-10-02  5:59 [Caml-list] beginner needs help creating a dynamically resizable array Ram Bhamidipaty
@ 2003-10-02  6:58 ` Michal Moskal
  2003-10-02  7:26 ` Nicolas Cannasse
  2003-10-02  9:58 ` Markus Mottl
  2 siblings, 0 replies; 4+ messages in thread
From: Michal Moskal @ 2003-10-02  6:58 UTC (permalink / raw)
  To: Ram Bhamidipaty; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] beginner needs help creating a dynamically resizable array
  2003-10-02  5:59 [Caml-list] beginner needs help creating a dynamically resizable array Ram Bhamidipaty
  2003-10-02  6:58 ` Michal Moskal
@ 2003-10-02  7:26 ` Nicolas Cannasse
  2003-10-02  9:58 ` Markus Mottl
  2 siblings, 0 replies; 4+ messages in thread
From: Nicolas Cannasse @ 2003-10-02  7:26 UTC (permalink / raw)
  To: Ram Bhamidipaty, caml-list

> I am trying to create a dynamically resizable array. So far this is what I
have:
[...]

You can use DynArray from the ExtLib :
http://sourceforge.net/projects/ocaml-lib

Nicolas Cannasse

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] beginner needs help creating a dynamically resizable array
  2003-10-02  5:59 [Caml-list] beginner needs help creating a dynamically resizable array Ram Bhamidipaty
  2003-10-02  6:58 ` Michal Moskal
  2003-10-02  7:26 ` Nicolas Cannasse
@ 2003-10-02  9:58 ` Markus Mottl
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Mottl @ 2003-10-02  9:58 UTC (permalink / raw)
  To: Ram Bhamidipaty; +Cc: caml-list

On Wed, 01 Oct 2003, Ram Bhamidipaty wrote:
> I am trying to create a dynamically resizable array. So far this is what I have:

You might want to try the RES-library:

  http://www.oefai.at/~markus/home/ocaml_sources.html#RES

Regards,
Markus Mottl

-- 
Markus Mottl          http://www.oefai.at/~markus          markus@oefai.at

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-10-02  9:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-02  5:59 [Caml-list] beginner needs help creating a dynamically resizable array Ram Bhamidipaty
2003-10-02  6:58 ` Michal Moskal
2003-10-02  7:26 ` Nicolas Cannasse
2003-10-02  9:58 ` Markus Mottl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).