[Grace-core] Encoding classes

James Noble kjx at ecs.vuw.ac.nz
Fri Jul 15 02:34:49 PDT 2011


> I continue to worry about whether we have a type-safe encoding of classes as objects with new methods.  Has anyone worked out the details?

Nope...

> However, we notice that all classes generating Pairs that have a constructor taking a pair of numbers have exactly the same type.  This may be fine, but is going to cause difficulty if our class has non-public methods.  For example, suppose PairClass has a private method "helper".
> 
> The problem arises when I want to override "helper":
> 
> class ExtPairClass {x, y -> extends PairClass.new(x,y)
>                                     <override> method helper(...) -> ... {...}
> }
> 
> As I see it, the type system has no way of knowing whether PairClass has a helper method or not and hence whether or not the override is legal.  In particular, if I replace all occurrences of PairClass in the above by another class that also has type PairClassType (but no helper method), it should type check with exactly the same result.

This is why we (currently)may only write "extends Classname.new(x,y)" 
Irrespective of the encoding (or otherwise) used to implement factories and classes,
so long as the subclass declaration (ExtPairClass) can only extend a manifest
superclass (PairClass) I don't see any problem.
 
Even if the private methods aren't in the type either of the factory or the instance objects
produced by the PairClass class declaration, ExtPairClass can still consult the PairClass
_declaration_ and get all the information there. 

> My point is that Classes are more than constructors and the public methods.  In my languages, the types of classes including all protected features as well as those that were public.  I'm not at all sure how that can be done with this encoding.

Right. It's not just override, there may be other annotations (we will need final or some analogue of that,
at least for some of the earlier "language levels") with consistency conditions across subclasses.
This is why I think classes can only inherit from classes.  If we want object extension, for practical reasons,
objects should be restricted to inherit only from classes too. 

> My conceptual model is like this: an object understands request for ALL of its methods, even the protected ones ("private" in your terminology).  So a class with a method _helper has a different type from a class without the method _helper.  

We could do it that way - I guess we have to decide, I don't know what's best.
I guess the question is: do we put *all* the information about a class into its type, or not? 

> (I don't recall if we settled on the prefix _  meaning protected or not).

No we didn't, and we didn't garner any discussion on the blog.
I had a few emails about it however, all of which made good points,
none of which agreed...

James


More information about the Grace-core mailing list