Browse thread
[Caml-list] Is a Cow an Animal?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Pixel <pixel@m...> |
| Subject: | [Caml-list] Is a Cow an Animal? |
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