



































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




































































All the objects in all the examples have type Counter (and sometimes more specific types).
But their internal representations vary widely.
An object is a record of functions, which maintain common internal state via a shared reference to a record of mutable instance variables. This state is inaccessible outside of the object because there is no way to name it. (Lexical scoping ensures that instance variable records can only be named inside the methods.)
Classes are data structures that can be both extended and instantiated. We modeled inheritance by copying implementations of methods from superclasses to subclasses. Each class I (^) waits to be told a record r of instance variables and an object this (which should have the same interface and be based on the same record of instance variables) I (^) uses r and this to instantiate its superclass I (^) constructs a record of method implementations, copying some directly from super and implementing others in terms of this and super. The this parameter is “resolved” at object creation time using fix.
We haven’t really captured the peculiar status of classes (which are both run-time and compile-time things) — we’ve captured the run-time aspect, but not the way in which classes get used as types in Java.
Also not named types with declared subtyping Nor recursive types
Nor run-time type analysis (casting, etc.) (... nor lots of other stuff)
Lots of different purposes −→ lots of different kinds of models I (^) Source-level vs. bytecode level I (^) Large (inclusive) vs. small (simple) models I (^) Models of type system vs. models of run-time features (not entirely separate issues) I (^) Models of specific features (exceptions, concurrency, reflection, class loading, ...) I (^) Models designed for extension
Purpose: model “core OO features” and their types and nothing else.
History: I (^) Originally proposed by a Penn PhD student (Atsushi Igarashi) as a tool for analyzing GJ (“Java plus generics”), which later became Java 1. I (^) Since used by many others for studying a wide variety of Java features and proposed extensions
I (^) Classes and objects I (^) Methods and method invocation I (^) Fields and field access I (^) Inheritance (including open recursion through this) I (^) Casting
class A extends Object { A() { super(); } }
class B extends Object { B() { super(); } }
class Pair extends Object { Object fst; Object snd;
Pair(Object fst, Object snd) { super(); this.fst=fst; this.snd=snd; }
Pair setfst(Object newfst) { return new Pair(newfst, this.snd); } }
Big dichotomy in the world of programming languages: I (^) Structural type systems: I (^) What matters about a type (for typing, subtyping, etc.) is just its structure. I (^) Names are just convenient (but inessential) abbreviations. I (^) Nominal type systems: I (^) Types are always named. I (^) Typechecker mostly manipulates names, not structures. I (^) Subtyping is declared explicitly by programmer (and checked for consistency by compiler).