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 BAA07202; Thu, 18 Apr 2002 01:40:28 +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 BAA07198 for ; Thu, 18 Apr 2002 01:40:27 +0200 (MET DST) Received: from leia.mandrakesoft.com (office.mandrakesoft.com [195.68.114.34]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3HNeQX20372 for ; Thu, 18 Apr 2002 01:40:26 +0200 (MET DST) Received: by leia.mandrakesoft.com (Postfix, from userid 505) id 7B9795B14; Thu, 18 Apr 2002 01:40:21 +0200 (CEST) To: caml-list@inria.fr Subject: [Caml-list] Is a Cow an Animal? From: Pixel Date: 18 Apr 2002 01:40:21 +0200 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Based on http://www.visviva.com/transframe/papers/covar.htm http://pauillac.inria.fr/~remy/work/virtual/virtual005.html I made http://merd.net/pixel/language-study/various/is-a-cow-an-animal/ and especially http://merd.net/pixel/language-study/various/is-a-cow-an-animal/ocaml2.listing Please help with some pbs! - 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) FYI the C++ version is: void is_human_food(const Food &food) { if (dynamic_cast(&food) == NULL && dynamic_cast(&food) == NULL) mythrow((string) "human doesn't accept food " + typeid(food).name()); } - I can't manage to create a "human" which would accept any type of "food", it only accepts exact "food", needing an upcast from "carrot"... to "food". using a parametric class for human: class ['a] human energy = object inherit [dead_human, 'a] animal energy (new dead_human) drop constraint 'a = #food method foo_human = () end it seems that 'a is free and gets infered with every use, ie after: a_human#eat carrot ; 'a is instanciated to carrot = < eaten : int; foo_carrot : unit > and refuses a_human#eat a_beef ; is it possible to *set* 'a to #food as wanted? thanks! -- Pixel programming languages addict http://merd.net/pixel/language-study/ ------------------- 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