just enough type theory or, featherweight java a simple formal model of objects jonathan aldrich...
TRANSCRIPT
![Page 1: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/1.jpg)
Just Enough Type Theory
or,
Featherweight JavaA Simple Formal Model of Objects
Jonathan Aldrich
15-819
![Page 2: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/2.jpg)
Why Formal Models?
• Make precise what a language means– What can you say in the language?– How does a program execute?
• Allow us to prove formal properties– Typically, lack of certain run-time errors
• This course– Type theory not required for much of the reading– However, some papers use formal notation
• A brief introduction will help us get more out of it
![Page 3: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/3.jpg)
Example: Featherweight Java
• A minimal core calculus for Java– Classes, methods, fields, inheritance– Any FJ program is a Java program
• Purpose of a core language– Leaves out unnecessary details– Focuses attention on issues of interest– Makes proving formal properties easier
• Citation– Atsushi Igarashi, Benjamin Pierce, and Philip Wadler.
Featherweight Java: A Minimal Core Calculus for Java and GJ. OOPSLA ’99.
![Page 4: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/4.jpg)
FJ Syntax
• Standard BNF definition• Overbar represents a sequence
![Page 5: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/5.jpg)
Subtyping Judgments
If we know this
Then we can conclude this
Base case: each class subtypes itself
Transitivity ruleBoth exprs on top must hold
![Page 6: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/6.jpg)
Dynamic Semantics
• Computation expressed as rewriting rules• [d/x] e – substitute d for x in e
![Page 7: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/7.jpg)
Evaluation Examples
![Page 8: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/8.jpg)
Type System
• Conceptually:– Annotates an object or expression– Describes operations that are applicable
• Prevents run-time errors from undefined operations– X = “hello” – 2– snail.fly()
• Type soundness– A well-typed program will not halt with an undefined operation
error• Java’s type system does a dynamic check at casts, and so
programs can halt with a cast error.• FJ’s type system, however prevents all other run time errors.
– Real languages have additional error cases; however, the type soundness guarantee is still useful
![Page 9: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/9.jpg)
FJ Types
maps var -> class
• Read ├ e C as, “in the context of type environment , expression e has type C
![Page 10: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/10.jpg)
Class/Method Typing
![Page 11: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/11.jpg)
Other definitions
![Page 12: Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich 15-819](https://reader036.vdocument.in/reader036/viewer/2022082821/5697c0101a28abf838ccb1bd/html5/thumbnails/12.jpg)
Type Soundness
A well-typed program remains well-typed after a reduction step
A well-typed program can take a step
Well-typed FJ programs eventually reduce to either a value or an expression with an embedded cast error
Proofs are by induction, beyond the scope of this course