Programming with Polymorphic Variants
Jacques Garrigue · 2010
Type inference for structural polymorphism ---i.e. record and variant polymorphism--- has been an active area of research since more than 10 years ago, and many results have been obtained. However these results are yet to be applied to real programming languages. Based on our experience with the Objective Label system, we describe how variant polymorphism can be integrated in a programming language, and what are the benefits. We give a detailed account of our type inference and compilation schemes. 1 Introduction The distinction between parametric polymorphism and ad hoc polymorphism is well known. In parametric polymorphism, e.g. ML polymorphism, types do not interact with evaluation, and polymorphic parts may be instantiated with anything, while in ad hoc polymorphism, with overloading or object-orientation, types do interact with evaluation, and possible instances are restricted. More subtle is the notion of structural polymorphism, i.e. the ability for a function to access dif...