Com S 641 Lecture -*- Outline -*- * Subtyping (Ch 8) ** overview subsumption is the notion that an object can emulate some object with fewer methods. Q: what's the relationship between objects and records? Q: why don't we want an operation to extract a method from an object? The subsumption described in this chapter is a simple one based on subtyping between object types. important theorems: minimum types, and subject-reduction ** type rules for subtyping (8.1) Q: what role does the type Top play in the type system? Q: is there anything surprising about the subtyping rule for function types? Q: is there anything surprising about the subtyping rule for object types? Q: is subtyping for object types recursive? discuss the notions of width and depth subtyping Q: what is the equivalent of the notion of context for types? Q: how are type contexts used to define covariance and contravariance, as well as invariance? Q: what can be said about the variance of function and object types? Q: does the subtyping relation form a total order? A partial order? Q: does every type have an upper bound? Q: could we define the meaning of the least upper bound of two types? Q: how does the difference in variance affect the translation of functions into objects from section 7.7? (It no longer preserves types) ** examples (8.2) Q: can you explain the subtyping in the cell example? Q: why doesn't to cell example from section 6.5.5 work? Q: can you give another example? ** properties of the calculus of subtyping *** minimum types Q: does this calculus have unique types? Q: what property could we use to replace that property? Q: how can that be formalized? Q: what is the difference between the MinOb_1 and Ob_1 systems? Q: does the MinOb_1 systems still have subsumption? Subtyping? Q: what are the advantages and disadvantages of using such a system? Q: how would you go about proving proposition 8.3-1? Q: how does this help prove that Ob_1<: has minimum types? Q: if we erase the type annotations from a term, does it still have a unique minimum type? Q: if we omit the type annotations on constant fields in objects do we still have unique minimum types? Q: is minimum typing important for practical purposes? *** subject reduction (8.3.2) Q: what is the importance of the bound weakening lemma? is it really weakening? Q: can you explain how the environment is used in the substitution lemma? Q: can we subsitutute a term having a subtype of the variable's type? Q: would that work in MinOb1<:? Q: explain the comment after the proof of the subject reduction theorem? ** First-order equational theories and subtyping (8.4) Q: in what sense does the type point of view matter for the equational theory? Can you give a concrete example? Q: how does the formal machinery reflect this? Q: in what sense does the formal system allow "an object " to be "truncated to its externally visible collection of methods, but only if those methods do not depend on the hidden ones"? Q: what is the problem with showing the equivalence of terms b and c at the top of page 100? ** classes and inheritance (8.5) *** representing class types and inheritance (8.5.1) Q: can you explain the meaning of the class types? Q: what is the relationship between inheritance and subtyping for class types? Q: what is the relation between the "may inherit from" relation and informal notion of inheritance? Q: what typing requirements apply to subclasses? Q: what does this have to say about fields of subclasses in practical programming languages like Java? *** variations on class types (8.5.2) Q: How is it possible to model abstract classes and abstract methods in a type safe way? Q: how could one model final classes in Java? Q: how do Abadi and Cardelli modify class types to take such considerations into account? Q: how can one model public, protected, and private methods? *** an example (8.5.3) Q: what does the private cell example say about the relationship between classes, traits and leaf classes? Q: what do the restricted cell and no contents cell examples say about subsumption and information hiding? Q: does information hiding depend on special type annotations? Q: or is the calculus powerful enough by itself? ** objects vs. records (8.6) This section discusses two extensions to the calculus Ob1<:, which make its type system unsound. These show that "object typing is fundamentally different from record typing" *** records (8.6.1) Q: how does the notation for records differ from that of objects? Q: what are the operations on records? Q: how is field update be "defined from the other operations"? Q: why can't that be done for the object calculus? Q: what are the differences between the record typing rules and the corresponding rules for objects? Q: what are the differences between the equational rules for records and those for objects? Q: how does the derived typing rule for record update differ from the typing rule for method update? *** method extraction (8.6.2) Q: how would you read the rules at the bottom of page 107? Q: why does the examples show that this is unsound? Q: why would this be sound if we do not have subsumption? *** Elder (8.6.3) Q: why would it be useful to refer to the previous value of a method during a method update? Q: what would the rules look like if we used a keyword "elder" instead of the form given in the text? Q: would there be any expressive power advantage or disadvantage? Q: what does elder have to do with method extraction? Q: why is it sound when method extraction is not? Q: how would you prove the soundness of elder? *** covariant object types (8.6.4) Q: what does the example show about depth subtyping for objects? Q: how do you explain that? ** variance annotations (8.7) *** object types with variance annotations (8.7.1) Q: what is a variance annotation? Q: what should the default be? Why? Q: how do you explain the subtyping rule? Q: what are the subtyping relationships between var = [get+:int, set-:int->var], acceptor = [set-:int->unit] and field = [get+:int] ? (this is like an abstract data type for variables) Q: why do the typing rules for selection and update have to change? *** encodings and examples with invariants (8.7.2) Q: why are the variance annotations what they are for products? Records? Q: why is the encoding of function types better with variance annotations? Q: how can variance annotations be used for preserving invariants? Q: how would you encode variant records using variance annotations? ** recursive types (chapter 9) we're going to skip this, but you might read: 9.1-2 and 9.4-6 if you don't have time for the whole chapter