From: Jerome Vouillon <vouillon@clipper.ens.fr>
To: Christian Boos <boos@arthur.u-strasbg.fr>
Cc: caml-list@inria.fr
Subject: Re: Q: about type inclusion
Date: Fri, 18 Apr 1997 15:34:58 +0200 (MET DST) [thread overview]
Message-ID: <Pine.SUN.3.95.970418151930.289A-100000@doris> (raw)
In-Reply-To: <199704091001.MAA28159@arthur.u-strasbg.fr>
Hello,
> I was at first puzzled by an error message saying "type x is not included
> in type y", because type x was a class inherited from class y, until I realized
> that there is two distinct notions of type inclusion in the langage :
> module type inclusion and class subtyping.
> However, I don't see why they couldn't mix, in particular on the example
> given at the end of this message.
There are two reasons for that. First, the abbreviations must remain
the same. In your example, type Bimpl.a expands to < a: int; b: int >,
whereas A.a would expand to < a: int >. Second, the method a (for
instance) is typed assuming that the type of self is an instance of
< a: int; b: int; .. >. In particular, method a could invoke method
b, and expect it to return an int. If your example did succeed, the
type of self in class A.a would only by constraint to be of the shape
< a: int; .. >, which is not correct: this is a more general type than
the previous one, and then nothing prevents you anymore to add a
method b of type bool in the subclass of A.a.
So, it is not possible to hide public methods a posteriori.
-- Jerome
> ------------------------------------------------------------------
>
> module type A =
> sig class a (unit) = method a : int end end
>
> module type B =
> sig class a (unit) = method a : int method b : int end end
>
>
> module Bimpl =
> struct class a () = method a = 1 method b = 2 end end
>
>
> module B = (Bimpl : B) (* of course *)
>
> (* but *)
>
> module A = (Bimpl : A)
>
> Characters 16-21:
> Signature mismatch:
> Modules do not match:
> sig class a (unit) = method a : int method b : int end end
> is not included in
> A
> Class types do not match:
> class a (unit) = method a : int method b : int end
> is not included in
> class a (unit) = method a : int end
> #
next prev parent reply other threads:[~1997-04-18 19:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-04-09 10:01 Christian Boos
1997-04-18 13:34 ` Jerome Vouillon [this message]
1997-06-23 9:46 ` Functors & Classes (was Re: Q: about type inclusion) Christian Boos
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=Pine.SUN.3.95.970418151930.289A-100000@doris \
--to=vouillon@clipper.ens.fr \
--cc=boos@arthur.u-strasbg.fr \
--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