Re: Q: about type inclusion

From: Jerome Vouillon (vouillon@clipper.ens.fr)
Date: Fri Apr 18 1997 - 15:34:58 MET DST


Date: Fri, 18 Apr 1997 15:34:58 +0200 (MET DST)
From: Jerome Vouillon <vouillon@clipper.ens.fr>
To: Christian Boos <boos@arthur.u-strasbg.fr>
Subject: Re: Q: about type inclusion
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
> #



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:10 MET