From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA13554; Tue, 18 Feb 2003 22:02:33 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA13534 for caml-list@pauillac.inria.fr; Tue, 18 Feb 2003 22:02:33 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA09699 for ; Mon, 17 Feb 2003 18:24:16 +0100 (MET) Received: from ep09.kernel.pl (ep09.kernel.pl [212.87.11.162]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h1HHOEP24859 for ; Mon, 17 Feb 2003 18:24:14 +0100 (MET) Received: (qmail 29593 invoked by uid 566); 17 Feb 2003 17:24:11 -0000 Date: Mon, 17 Feb 2003 18:22:25 +0100 From: Michal Moskal To: inv2002 Cc: caml-list@inria.fr Subject: Re: [Caml-list] object Message-ID: <20030217172225.GB12324@roke.freak> References: <3E50A804.000001.28592@camay.yandex.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3E50A804.000001.28592@camay.yandex.ru> User-Agent: Mutt/1.4i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, Feb 17, 2003 at 12:14:44PM +0300, inv2002 wrote: > class virtual obj = object > ... > end > > class a_obj = object > inherit obj > method a_fun = ... > end > > class b_obj = object > inherit obj > method b_fun = ... > end > > class object_list = object > val ht = Hashtbl.create 5 > > method add: 'a. string -> (#obj as 'a) -> unit = fun key o -> > Hashtbl.add ht key (o :> obj) (* i don't know right way, how to store objects *) > > method find key = > Hashtbl.find ht key > > end > > i want to store a_obj and b_obj in object_list, > after find it and execute a_fun method > if the object is a_obj How do you know object is really of type a_obj? There are few solutions: 1. type a_or_b_obj = A_obj of a_obj | B_obj of b_obj method add k o = Hashtbl.add ht k o foo#add (A_obj a) foo#add (B_obj b) 2. add a_fun and b_fun with ,,assert false'' like implementation 3. use Obj.magic First solution gives you static typing, second gives you dynamic typing, and third -- no typing. -- : Michal Moskal ::::: malekith/at/pld-linux.org : GCS {C,UL}++++$ a? !tv : PLD Linux ::::::: Wroclaw University, CS Dept : {E-,w}-- {b++,e}>+++ h ------------------- 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