[
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: | John Max Skaller <skaller@o...> |
| Subject: | Re: [Caml-list] Is a Cow an Animal? |
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