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] a design problem requiring downcasting? (long)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-09-26 (14:32)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] a design problem requiring downcasting? (long)
Michael Vanier <> writes:


>  These method calls are highly dependent on the
> specific types of the objects.  If you create the objects like this:
>   let obj1 = new class1 in
>   let obj2 = new class2 in
>   obj1#my_method obj2
> then everything works.  However, it is not feasible, when writing a
> simulation with this many objects, to keep unique identifiers to each object
> that you create.  Therefore, you need some kind of data structure to store
> objects after you create them.  For our purposes we can assume that there is
> a big master array of these objects.  I see two alternatives for the types of
> the array elements.
> 1) All elements will be instances of subclasses of a base type "base".  The
>    array will have the type "base array".
> 2) The array will be of type "anObject array", where anObject is a variant type
>    that can hold the type of any simulation object.
> With alternative (1), to do the method call above you would need downcasting
> e.g. in pseudo-ocaml:
>   let obj1 = array.(0) as class1 in
>   let obj2 = array.(1) as class2 in
>   obj1#my_method obj2

Well, my problem when I read this is the foolowing : How do you know
that you have to call the method my_method of the #2341 object with
the #5232 as argument ?

This information is somewhere (It can't come from nowhere) so There
the type information could be stored (I mean, may be you could put
there not the position of the object in the array, but the object

Otherwise there is severall way to make downcast in caml : you could
look to coca-ml
or to the hweak library (


Rémi Vanicat
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: