Traditionally, typed objects have been encoded as records; the fields and methods of an object are stored in the fields of a record and projected when needed. While the dual approach of using variants instead of records has been explored, it is more challenging to type: the output type of a variant case match must depend on the input value; this is a form of dependent typing.

In this paper, we construct a variant-based encoding of objects which is statically typeable and which improves on the flexibility of typed object models in several dimensions: messages can be represented as simple first-class data, object extension is more generally typeable than in previous systems and, arguably, a better integration of objects and functions is obtained.

This encoding is possible due to the features of our new core language, TinyBang, which incorporates a subtype constraint type inference system with several novel extensions. We develop a generalized notion of first-class cases – functions with an inherent pattern match that are composable – and we extend previous notions of conditional constraint types to obtain accurate typings. For added flexibility, TinyBang’s record-like structure is type-indexed, meaning data can be projected based on its type alone. Our record structure’s concatenation operator is asymmetric by default, naturally supporting object extension. Finally, we develop a refined notion of parametric polymorphism which aims to achieve a good combi- nation of flexibility and efficiency of inference.