<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/07/2d76bfee0b5a11a7db9f49191f910099"
  from="Olivier Ricordeau &lt;olivier.ricordeau@w...&gt;"
  author="Olivier Ricordeau"
  date="2003-07-22T17:45:32"
  subject="Re: [Caml-list] match on dynamic type"
  prev="2003/07/8d172d820e65f0b1a595f47107efe83b"
  next="2003/07/7347ef3d79f516ef8692babe85c8791a"
  prev-in-thread="2003/07/8d172d820e65f0b1a595f47107efe83b"
  prev-thread="2003/07/efc650f6736621d6f758bb8de52b1496"
  next-thread="2003/07/7347ef3d79f516ef8692babe85c8791a"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] match on dynamic type">
<msg 
  url="2003/07/f4f0c2155e99d8e24366c19287802309"
  from="Olivier Ricordeau &lt;olivier.ricordeau@w...&gt;"
  author="Olivier Ricordeau"
  date="2003-07-22T15:52:09"
  subject="[Caml-list] match on dynamic type">
<msg 
  url="2003/07/8d172d820e65f0b1a595f47107efe83b"
  from="Olivier Ricordeau &lt;olivier.ricordeau@w...&gt;"
  author="Olivier Ricordeau"
  date="2003-07-22T16:26:59"
  subject="Re: [Caml-list] match on dynamic type">
<msg 
  url="2003/07/2d76bfee0b5a11a7db9f49191f910099"
  from="Olivier Ricordeau &lt;olivier.ricordeau@w...&gt;"
  author="Olivier Ricordeau"
  date="2003-07-22T17:45:32"
  subject="Re: [Caml-list] match on dynamic type">
</msg>
</msg>
</msg>
</thread>

<contents>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Olivier Ricordeau wrote:
&gt;&gt;Hi!
&gt;&gt;I'd like to know how I can make a match on an object's dynamic type. Let
&gt;&gt;a be an abstract class. Let b and c be two class which inherit from a.
&gt;&gt;I'd like to write a method which looks like this:
&gt;&gt;
&gt;&gt;method foo (bar : a) =
&gt;&gt;    match "a's dynamic type" with
&gt;
&gt; I meant:
&gt;       match "bar's dynamic type" with
&gt;
&gt;
&gt;&gt;       b -&gt; do_something()
&gt;&gt;     | c -&gt; do_something_else()

According to two mails I've just received from members of this list:
- -&gt; This cannot be done with OCaml
- -&gt; The trick is to add an string attribute (non-mutable) which contains
the dynamic type to the mother class.

Thanks to Basile Starynkevitch and Richard Jones for their help.

- --
- -= *Olivier RICORDEAU* =-        http://freefolks.org
          &lt; LibNN addict http://libnn.org &gt;
lynx -source http://freefolks.org/key.asc | gpg --import
olivier.ricordeau@wanadoo.fr _Might the source be with you_
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/HXgZDFRYKP6DJEwRAnFNAJ0UkMPQ2k7OgTIF6D9GYn3FGpAh2wCfW8wl
OI6wM1qf2StTgaJO+uFhnMQ=
=jLY1
-----END PGP SIGNATURE-----

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

</contents>

</message>

