caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Remi VANICAT <vanicat@labri.u-bordeaux.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] a design problem requiring downcasting? (long)
Date: 26 Sep 2002 16:32:18 +0200	[thread overview]
Message-ID: <ya3it0sddot.dlv@serveur4.labri.fr> (raw)
In-Reply-To: <200209260901.g8Q910t03459@orchestra.cs.caltech.edu>

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


  reply	other threads:[~2002-09-26 14:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-26  9:01 Michael Vanier
2002-09-26 14:32 ` Remi VANICAT [this message]
2002-09-26 15:19 ` nadji
2002-09-26 15:27   ` Remi VANICAT
2002-09-26 15:55     ` nadji
2002-09-26 15:53 ` Jeffrey Palmer
2002-09-26 16:35 ` Oleg
2002-09-26 17:47 ` brogoff
2002-09-26 19:14 ` Fred Smith
2002-09-27 17:01   ` Tim Freeman
2002-09-26 22:46 ` Alessandro Baretta
2002-09-27  7:20 ` Francois Pottier
2002-09-27 10:16   ` Michael Vanier
2002-09-29 22:59     ` Alessandro Baretta
2002-09-30  7:09       ` Michael Vanier
2002-09-30  9:54         ` Alessandro Baretta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ya3it0sddot.dlv@serveur4.labri.fr \
    --to=vanicat@labri.u-bordeaux.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).