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] match on dynamic type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Olivier Ricordeau <olivier.ricordeau@w...>
Subject: Re: [Caml-list] match on dynamic type
Hash: SHA1

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

According to two mails I've just received from members of this list:
- -> This cannot be done with OCaml
- -> 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* =-
          < LibNN addict >
lynx -source | gpg --import _Might the source be with you_
Version: GnuPG v1.2.2 (GNU/Linux)


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: