caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Max Skaller <skaller@ozemail.com.au>
To: Pixel <pixel@mandrakesoft.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Is a Cow an Animal?
Date: Thu, 18 Apr 2002 12:17:44 +1000	[thread overview]
Message-ID: <3CBE2CC8.1030407@ozemail.com.au> (raw)
In-Reply-To: <lyzo01q4gq.fsf@leia.mandrakesoft.com>

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


  reply	other threads:[~2002-04-18  2:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-17 23:40 Pixel
2002-04-18  2:17 ` John Max Skaller [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3CBE2CC8.1030407@ozemail.com.au \
    --to=skaller@ozemail.com.au \
    --cc=caml-list@inria.fr \
    --cc=pixel@mandrakesoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).