caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pixel <pixel@mandrakesoft.com>
To: caml-list@inria.fr
Subject: [Caml-list] Is a Cow an Animal?
Date: 18 Apr 2002 01:40:21 +0200	[thread overview]
Message-ID: <lyzo01q4gq.fsf@leia.mandrakesoft.com> (raw)

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


             reply	other threads:[~2002-04-17 23:40 UTC|newest]

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

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=lyzo01q4gq.fsf@leia.mandrakesoft.com \
    --to=pixel@mandrakesoft.com \
    --cc=caml-list@inria.fr \
    /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).