Isaac Newton Institute for Mathematical Sciences

Semantics of Computation

Semantics of Computation Seminar

Wednesday September 20, 11:00 am

Using Types to Compare Objects and ADTs

Benjamin C. Pierce
Computer Lab, Cambridge

Objects and Abstract Data Types are popular techniques for code organization and information hiding in large-scale programming. Each has been thoroughly studied, and their relative pragmatic benefits are often discussed, yet a precise comparison remains elusive due to the lack of common conceptual frameworks.

We offer typed lambda-calculus as such a framework. Beginning from Mitchell and Plotkin's well-known correspondence between ADTs and existential types, we draw a similar correspondence between objects and a slightly different usage of existential types, following earlier work by Pierce, Turner, and Hofmann. Both styles of "programming with existentials" involve packing a hidden representation type together with a group of associated operations. The variation is one of scope: in the case of an ADT, the package is opened immediately after it is built; objects are opened only when their operations are invoked.

Familiar differences between objects and ADTs (involving subtyping, binary methods, etc.) are readily visible in this setting. Moreover, the simple initial formulations can be extended naturally with additional features such as mutable state, recursive interface types, and inheritance.