Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] a design problem requiring downcasting? (long)
Michael Vanier <mvanier@cs.caltech.edu> 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
itself). 

Otherwise there is severall way to make downcast in caml : you could
look to coca-ml
(http://www.pps.jussieu.fr/~emmanuel/Public/Dev/coca-ml/index-en.html)
or to the hweak library (http://aspellfr.free.fr/)


 

-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
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