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 IAA18481; Wed, 31 Mar 2004 08:45:19 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 IAA18964 for ; Wed, 31 Mar 2004 08:45:18 +0200 (MET DST) From: briand@aracnet.com Received: from obsidian.spiritone.com (obsidian.spiritone.com [216.99.193.137]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i2V6k0jq022078 for ; Wed, 31 Mar 2004 08:46:01 +0200 Received: from soggy.deldotd.com (216-99-206-32.cust.aracnet.com [216.99.206.32]) by obsidian.spiritone.com (8.12.10/8.12.8) with ESMTP id i2V6sJ63013869; Tue, 30 Mar 2004 22:54:20 -0800 Received: from briand by soggy.deldotd.com with local (Exim 3.36 #1 (Debian)) id 1B8ZTK-00031Q-00; Tue, 30 Mar 2004 22:45:10 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16490.26870.331855.463270@soggy.deldotd.com> Date: Tue, 30 Mar 2004 22:45:10 -0800 To: Matt Gushee Cc: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] examples of heterogenous collections (containers ?) In-Reply-To: <20040331054113.GC19538@swordfish> References: <16490.20296.852406.613011@soggy.deldotd.com> <20040331054113.GC19538@swordfish> X-Mailer: VM 6.92 under Emacs 21.2.1 X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 gushee:01 mgushee:01 havenrock:01 non-trivial:01 subtyping:01 didier:01 remy's:01 appsem:01 arbitrarily:01 iterating:01 invoke:01 bool:01 ocaml:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >>>>> "Matt" == Matt Gushee writes: Matt> This will work if all the classes have identical signatures. Of course, Matt> that's not the case for most non-trivial examples. The classes have identical signatures, i.e. all have exactly the same methods and variables ?? Matt> Probably not. First of all, you will need to cast the objects at the Matt> point where you put them into a list together ... thus, at the point Matt> where you do the method call, the cast has already been done. Second, Matt> you don't necessarily want to cast them to the base class. Well that makes sense, if I can figure out the part about all the classes havin g the same signature. Matt> As some people never tire of pointing out ;-), inheritance is Matt> not subtyping. Actually, I haven't myself figured out all the Matt> implications of that statement, nor learned the theoretical Yes, I've been seeing that, and amazingly it's actually starting to sink in. There are some notes from the ocaml page which discuss this relatively well : Didier Remy's APPSEM course notes on Objective Caml. Matt> justification for it--but at any rate, in OCaml class types Matt> are completely independent of inheritance Matt> relationships. That's a good thing because it means you can Matt> define a class type and arbitrarily apply it to any class that Matt> provides *at least* the methods specified in the type Matt> signature, regardless of inheritance. E.g.: Matt> class type x = Matt> object Matt> method a : unit Matt> method b : int -> bool Matt> end Matt> ... and so on. ??? So it's example time : class virtual base = ... end class A1 = object(self) inherit base method x1 = ... method x2 = ... end class A2 = object(self) inherit base method x1 = ... method x2 = ... method x3 = ... end So I should be able to do : let a = new A1 in let b = new A2 in (a :> base) :: (b :> base) :: [] ;; right ? now my list has type "base list". So I immediately see the problem here. My iter code could try to invoke method x3 on the A1 object in the list as I'm iterating through. oops. So it seems to me that I need a "stronger" method to enforce safety, perhaps implementing x1 as a virtual method in base ? Brian ------------------- 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