Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Ian T Zimmerman <itz@rahul.net>
To: caml-list@pauillac.inria.fr
Subject: ocaml, inheritance vs. subtyping?
Date: Sat, 1 Jun 1996 16:19:02 -0700	[thread overview]
Message-ID: <199606012319.QAA00493@kronstadt.rahul.net> (raw)


Hi, I am just starting with ocaml, so please have mercy on a newbie
:-)

I am somewhat perplexed by the passage in the manual on virtual
methods (pp. 29-30).  Let's start with the first paragraph on p.30: it
says that int_comparable2 is not a subtype of int_comparable, even
though the former inherits from the latter!  Now for a person with an
experience in a non-functional OO language (C++ or Eiffel or Sather)
it seems _very strange_ that the subtype and inheritance (derivation)
relations aren't the same.  It even seems that not having such an
overlap defeats the purpose of having OO features in the first place.
How is the programmer to predict where a subtype relation actually
exists?

Now the manual goes on to say that this occurs because `the self type
appears in contravariant position in the type of method leq'.  First,
am I right in decoding this as `the types of the argument of
int_comparable#leq and int_comparable2#leq are in covariant relation,
but they would have to be in contravariant relation for a subtyping
relation to exist between int_comparable and int_comparable2'?
Second, and this may be the heart of the issue, _WHY_ is type 'a ->
bool inferred for leq, and not < x: unit -> int; .. > -> bool , as
it surely would for a global function?

If these are stupid questions, I apologize again.  Maybe it's a sign
that the OO features need more explanation in the manual, though.

Best,

-- 
Ian T Zimmerman           +-------------------------------------------+
Box 13445                 I When the dead are left to bury the dead,  I
Berkeley CA 94712 USA     I the living remain alone.  Arthur Koestler I
mailto:itz@rahul.net      +-------------------------------------------+





             reply	other threads:[~1996-06-03  7:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-01 23:19 Ian T Zimmerman [this message]
1996-06-03 17:52 ` Didier Remy
     [not found] ` <199606031649.SAA14505@pauillac.inria.fr>
1996-06-04  6:51   ` Ian T Zimmerman

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=199606012319.QAA00493@kronstadt.rahul.net \
    --to=itz@rahul.net \
    --cc=caml-list@pauillac.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