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 EAA08857; Thu, 18 Apr 2002 04:17:58 +0200 (MET DST) 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 EAA08853 for ; Thu, 18 Apr 2002 04:17:56 +0200 (MET DST) Received: from vasquez.zip.com.au (vasquez.zip.com.au [203.12.97.41]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3I2HrX24044 for ; Thu, 18 Apr 2002 04:17:54 +0200 (MET DST) Received: from ozemail.com.au (ppp248.dyn20.pacific.net.au [61.8.20.248]) by vasquez.zip.com.au (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id MAA03747; Thu, 18 Apr 2002 12:17:44 +1000 X-Authentication-Warning: vasquez.zip.com.au: Host ppp248.dyn20.pacific.net.au [61.8.20.248] claimed to be ozemail.com.au Message-ID: <3CBE2CC8.1030407@ozemail.com.au> Date: Thu, 18 Apr 2002 12:17:44 +1000 From: John Max Skaller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: Pixel CC: caml-list@inria.fr Subject: Re: [Caml-list] Is a Cow an Animal? References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Pixel wrote: > >- since class equivalence is based on methods and not on class-name, I have to >put dummy methods for ensuring the subtyping relation. >Is there a nicer/official way? > >- I know one can't downcast, but is there no way to have some RTTI? must it be >done by hand? (adding a C++-typeinfo-like method) > You ask in the title "Is a cow an animal?". The answer is no. Use a variant, give up on classes: type Animal = Horse of horse | Cow of cow type horse = Shetland of shetland | Arabian of arabian ... That is a heterogenous tree structure modelling the taxonomy. There is no polymorphism here. There is no subtyping. It is pretty much the exact opposite: this is unification, the aggregation of utterly distinct types into a common type. You can do a bit better sometimes, by recognising some commonality: type Animal = { animal_common:animal_part; animal_variant:animal_split } type animal_split = Horse of horse | Cow of cow ... so that the horse type only contains features unique to horses. But you should really forget abstraction, and just build concrete data structures: its really just a large in memory database, after all: you really won't gain much hiding the representation here. >-- >John Max Skaller, mailto:skaller@ozemail.com.au >snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. >voice:61-2-9660-0850 > > ------------------- 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