Principles of Object-Oriented Software Development
[] readme course preface 1 2 3 4 5 6 7 8 9 10 11 12 appendix lectures resources

# Summary

This chapter has treated polymorphism from a foundational perspective. In section 1, we looked at abstract inheritance as employed in knowledge representation.

#### Abstract inheritance

1

• abstract inheritance -- declarative relation
• inheritance networks -- non-monotonic reasoning
• taxonomic structure -- predicate calculus

slide: Section 9.1: Abstract inheritance

We discussed the non-monotonic aspects of inheritance networks and looked at a first order logic interpretation of taxonomic structures.

#### The subtype relation

2

• types -- sets of values
• the subtype relation -- refinement rules
• functions -- contravariance
• objects -- as records

slide: Section 9.2: The subtype relation

In section 2, a characterization of types as sets of values was given. We looked at a formal definition of the subtype relation and discussed the refinement rules for functions and objects.

#### Flavors of polymorphism

3

• typing -- protection against errors
• inheritance -- incremental modification mechanism

slide: Section 9.3: Flavors of polymorphism

In section 3, we discussed types as a means to prevent errors, and distinguished between various flavors of polymorphism, including parametric polymorphism, inclusion polymorphism, overloading and coercion. Inheritance was characterized as an incremental modification mechanism, resulting in inclusion polymorphism.

#### Type abstraction

4

• subtypes -- typed lambda calculus
• bounded polymorphism -- generics and inheritance

slide: Section 9.4: Type abstraction

In section 4, some formal type calculi were presented, based on the typed lambda calculus. These included a calculus for simple subtyping, a calculus for overloading, employing intersection types, and a calculus for bounded polymorphism, employing type abstraction. Examples were discussed illustrating the (lack of) features of the C++ type system.

#### Existential types

5

• hiding -- existential types
• packages -- abstract data types

slide: Section 9.5: Existential types

In section 5, we looked at a calculus employing existential types, modeling abstract data types and hiding by means of packages and type abstraction.

#### Self-reference

6

• self-reference -- recursive types
• object semantics -- unrolling
• inheritance -- dynamic binding
• subtyping -- inconsistencies

slide: Section 9.6: Self-reference

Finally, in section 6, we discussed self-reference and looked at a calculus employing recursive types. It was shown how object semantics may be determined by unrolling, and we studied the semantic interpretation of dynamic binding. Concluding this chapter, an example was given showing an inconsistency in the Eiffel type system.

# Questions

1. How would you characterize inheritance as applied in knowledge representation? Discuss the problems that arise due to non-monotony.
2. How would you render the meaning of an inheritance lattice? Give some examples.
3. What is the meaning of a type? How would you characterize the relation between a type and its subtypes?
4. Characterize the subtyping rules for ranges, functions, records and variant records. Give some examples.
5. What is the intuition underlying the function subtyping rule?
6. What is understood by the notion of objects as records? Explain the subtyping rule for objects.
7. Discuss the relative merits of typed formalisms and untyped formalisms.
8. What flavors of polymorphism can you think of? Explain how the various flavors are related to programming language constructs.
9. Discuss how inheritance may be understood as an incremental modification mechanism.
10. Characterize the simple type calculus $%l_\left\{<=\right\}$, that is the syntax, type assignment and refinement rules. Do the same for $F_\left\{ /\ \right\}$ and $F_\left\{<=\right\}$.
11. Type the following expressions: (a) $\left\{ a = 1, f = %l x:Int. x + 1 \right\}$, (b) $%l x:Int . x * x$, and (c) $%l x:\left\{ b:Bool, f:\left\{ a:Bool \right\} \right\} -> Int.x.f\left(x\right)$.
12. Verify whether: (a) $f\text{'} : 2..5 -> Int <= f:1..4 -> Int$, (b) $\left\{ a:Bool, f:Bool -> Int \right\} <= \left\{ a:Int, f: Int -> Int \right\}$, and (c) $%l x: \left\{ a:Bool \right\} -> Int <= %l x: \left\{ a:Bool, f:Bool -> Int \right\} -> Int$.
13. Explain how you may model abstract data types as existential types.
14. What realizations of the type $\E %a. \left\{ a:%a, f:%a -> Bool \right\}$ can you think of? Give at least two examples.
15. Prove that $%m %a . \left\{ c:%a, b:%a -> %a \right\} \not<= %m %a . \left\{ b : %a -> %a \right\}$.
16. Prove that $%m %a . \left\{ c : %a, b: %t -> %a \right\} <= %t$, for $%t = %m %a.\left\{ b: %a -> %a \right\}$.

slide: Questions