Version française
Home     About     Download     Resources     Contact us    
Browse thread
Q: about type inclusion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jerome Vouillon <vouillon@c...>
Subject: Re: Q: about type inclusion


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
> #