Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Didier Remy <Didier.Remy@inria.fr>
To: Giuseppe Castagna <Giuseppe.Castagna@ens.fr>
Cc: caml-list@inria.fr, mottl@miss.wu-wien.ac.at
Subject: Re: subtyping and inheritance
Date: Wed, 21 Apr 1999 14:18:36 +0200	[thread overview]
Message-ID: <19990421141836.40591@morgon.inria.fr> (raw)
In-Reply-To: <371C97FE.B8B5010D@ens.fr>; from Giuseppe Castagna on Tue, Apr 20, 1999 at 05:06:38PM +0200

> I completely agree, it is quite difficult (maybe impossible) to do it if you
> want it fully general. 

Beppe, 

You won't be surprised if I tell you that I don't like special cases a lot.
Moreover, I don't really know where and how to draw a clear border. Even on
the particular example of money that you took, things are not so simple....

----------------

Typechecking of classes in Ocaml is (relatively) simple because it relies
only on polymorphism and not on subtyping. Subtyping comes later and it is
not essential. In particular, if you never use explicit coercions, there is
actually no subtyping involved at all, and most examples still typecheck,
including binary methods (and much more)!  As a result of this simple
approach, the type of self in a subclass is just an instance of the type of
self in its parent class.

I suspect that you will have to give up this invariant since your approach
is, conversely, based on subtyping and not on polymorphism.  Then, you may
be loosing much of the simplicity or just be unable to formalize the
``patch'' as an ``extension'' of Ocaml.

> # class money2 x =
>     object 
>       inherit money x
>        method dynamic leq (p:'mytype) = repr <= (p#value -. p#square)
>        method square  = repr *. repr
>     end;;

[the type annotation on "p" is useless you bound "'mytype" as the type of
self in "object (_ : 'mytype)"]

What type do you wish to give to that class? In particular, what should be
the (static) type of an object of that class?

> What the "dynamic" modifier means? First of all, it means that money2 is a
> subtype of money (that is it allows contravariant occurrences of
> 'mytype). 

Another essential matter is that type comparisons in Ocaml are structural,
as opposed to by-name: this applies to both type equality and
subtyping. Thus, you cannot just ``make'' money2 a subtype of money. Then,
how would you define the subtyping relation so that the type money2 is a
subtype of money?

In conclusion, I think that even when restricting to a small subcase of the
general problem the solution, if it exists as an extension of Ocaml, is not
easy. In any case, I would be very happy to see it on paper...

Cheers,

        -Didier




  reply	other threads:[~1999-04-21 16:58 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-15 12:18 Giuseppe Castagna
1999-04-15 16:02 ` Markus Mottl
1999-04-20 12:38 ` Didier Remy
1999-04-20 15:06   ` Giuseppe Castagna
1999-04-21 12:18     ` Didier Remy [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-01-11 18:52 Markus Mottl
1999-01-15 15:02 ` Jerome Vouillon
1999-01-15 17:37   ` Markus Mottl
1999-01-18 19:55     ` Jerome Vouillon
1999-01-18 21:18       ` Markus Mottl
1999-01-20 11:50         ` Hendrik Tews
1999-01-25  0:08           ` Markus Mottl
1999-01-27 14:18             ` Jerome Vouillon
1999-01-27 14:45               ` Markus Mottl
1999-01-28 19:40               ` Hendrik Tews
1999-01-27 14:28           ` Jerome Vouillon

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=19990421141836.40591@morgon.inria.fr \
    --to=didier.remy@inria.fr \
    --cc=Giuseppe.Castagna@ens.fr \
    --cc=caml-list@inria.fr \
    --cc=mottl@miss.wu-wien.ac.at \
    /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