Native Typestate Workshop
(1) Describe the problem you would like to solve. Include a
set of research questions.
Libraries are critical to modern software development.
As we know, using them is often difficult and error-prone.
We have developed typestate as a way of tracking object protocols to
document and check correct usage of libraries.
But typestate is layered on top of existing languages, restricting
flexibility and substantially complicates the type system
Research questions:
* Is it possible to merge types and typestate into a single,
simpler idea?
* Is it possible to have a different representation for each
typestate, not just a different invariant?
(2) Show one or more concrete examples of the problem you would
like to solve.
class ClosedFile { ... }
class OpenFile { ... }
function Open(f : ClosedFile => OpenFile) = ...
function Read(f : OpenFile) = ...
var myFile = new ClosedFile();
myFile.Open();
myFile.Read();
(3) Describe conditions under which you will have solved the
problem for at least one such example
If I can develop a syntax that can represent the example above, and
typing rules capable of typechecking the code above, the problem is
solved for this example.
Eventually need an operational semantics - only way to show the types
are consistent.
(4) Discussion
Is it like passing by reference? Sort of, but
not assigning to var - changing object state
Related: ML datatypes with type refinements that
tell you what branch you're in
What happens if there's an error Opening the
file? What is the class of f?
throw an exception & leave f
unchanged? how to specify?
return an option or an ErrorFile?
Related: predicate classes - but they are not static
and do not permit alternate representations
Multiple inheritance or union types - a way to get
orthogonal dimensions of state
Additional advantage: can dispatch on the classes
(like predicate classes)
Need to add inheritance - want to talk about File
not OpenFile sometimes
and polymorphism - for all states
T return in same state T
intersection types - useful for exceptions,
different state changes
(5) Describe your proposed solution approach
Language features:
* The lambda calculus
* Classes that have a representation and a permission invariant
* Linear permissions that tell you what class an object has at
any given point
* new to create an object of a given class
* unpack to get at a class's representation
* become to repack an object, potentially to a new class with a
new representation
See language and typing rules in native-typestate.slf.
(6) Illustrate your proposed solution approach on the concrete
example.
See example in native-typestate.slf.
(7) Discussion
Become subsumes references
(8) If time, discuss future directions
- operational semantics
- full set of rules
- typecheck and execute this example and also others
- expand to include store
- extend to allow multiple clients
- add subtyping between classes
- soundness proof
- extend to relationships