caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Is a Cow an Animal?
@ 2002-04-17 23:40 Pixel
  2002-04-18  2:17 ` John Max Skaller
  2002-04-18 18:58 ` james woodyatt
  0 siblings, 2 replies; 12+ messages in thread
From: Pixel @ 2002-04-17 23:40 UTC (permalink / raw)
  To: caml-list

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<const Carrot*>(&food) == NULL &&
      dynamic_cast<const Meat*>(&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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2002-04-19  0:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-17 23:40 [Caml-list] Is a Cow an Animal? Pixel
2002-04-18  2:17 ` John Max Skaller
2002-04-18 10:19   ` Pixel
2002-04-18 12:09     ` Pixel
2002-04-18 12:52       ` Jacques Garrigue
2002-04-18 13:03         ` Pixel
2002-04-18 18:58 ` james woodyatt
2002-04-18 22:44   ` Pixel
2002-04-18 22:57     ` james woodyatt
2002-04-18 23:31       ` Pixel
2002-04-19  0:21   ` Remi VANICAT
2002-04-19  0:51     ` james woodyatt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).