ACM Home Page
Please provide us with feedback. Feedback
Polymorphic type inference
Full text PdfPdf (1.01 MB)
Source Annual Symposium on Principles of Programming Languages archive
Proceedings of the 10th ACM SIGACT-SIGPLAN symposium on Principles of programming languages table of contents
Austin, Texas
Pages: 88 - 98  
Year of Publication: 1983
ISBN:0-89791-090-7
Author
Daniel Leivant  Carnegie-Mellon University
Sponsors
SIGPLAN: ACM Special Interest Group on Programming Languages
SIGACT: ACM Special Interest Group on Algorithms and Computation Theory
Publisher
ACM  New York, NY, USA
Bibliometrics
Downloads (6 Weeks): 6,   Downloads (12 Months): 55,   Citation Count: 39
Additional Information:

abstract   references   cited by   collaborative colleagues  

Tools and Actions: Request Permissions Request Permissions    Review this Article  
DOI Bookmark: Use this link to bookmark this Article: http://doi.acm.org/10.1145/567067.567077
What is a DOI?

ABSTRACT

The benefits of strong typing to disciplined programming, to compile-time error detection and to program verification are well known. Strong typing is especially natural for functional (applicative) languages, in which function application is the central construct, and type matching is therefore a principal program correctness check. In practice, however, assigning a type to each and every expression in a functional program can be prohibitively cumbersome. As expressions are compounded, the task of assigning a type to each expression and subexpression becomes practically impossible, even more so because the type-expressions themselves grow longer. It becomes imperative therefore to design friendly programming environments that permit the user type-free programming, but that generate fully typed programs in which the types of all expressions are inferred by the system from the program. For interactive functional programming environments of the kind implemented for the Edinburgh functional programming language ML, a type-inference system is an invaluable tool for on-line parse-time error detection and debugging.

The issue of type inference leads naturally to type-schemes. If all one has of a functional program is a definition statement such as f(x)=3, then all one can say of the type of f is that it must be of the form ’Ѩint, i.e. --- an instance of the type scheme t ¨ int, where t is a type variable. As more of the program appears, say x(true)=z, t may be restricted, to bool¨s. We are therefore interested in type-schemes, using type parameters (free type variables). All one needs then to obtain a rudimentary form of generic procedures is a device for type instantiation. This function is fulfilled in ML by the construct let. Other methods are described in Ü4 below.

During the process of inferring a type for a given program, one would like at each step to find a most general (so-called principal) type scheme for each subexpression, so that types to be assigned to variables and subexpressions in the sequel may be assumed to be instances of those assigned earlier. The notion of principal type was introduced by Curry and Feys [CF] for Combinatory Logic, and Hindley [Hin] showed that the principal type exists for any Combinatory Logic expression and that it can be found using J.A. Robinson's Unification algorithm [Rob].The seminal paper on type-inference for functional programs is Milner's [Mil], where an algorithm W is defined for inferring a type for any ML program (without recursively defined types). More recently, Damas and Milner [DM] defined a simple formal calculus of type inference, with respect to which W is proved complete.

In this paper we study several aspects of type inference for polymorphic type disciplines. First, we deal with type inference for parametric type systems, that is --- type systems that include simple types defied over constant types and type variables. We recast Milner's algorithm W in a general "algebraic" form, which applies to a variety of generic type disciplines (Ü2). In Ü3 we present an alternative algorithm V for type inference, fundamentally different from W, which easily accommodates type coercion and overloading, allows efficient local updates to the user program, and is more efficient than W for implementations that allow concurrency.

In Ü4 we briefly describe four polymorphic disciplines: type abstraction, type quantification, type conjunction (intersection) and the ML construct let.

In Ü5 type inference for the abstraction and quantification disciplines is discussed. We point out that the two disciplines are combinatorially isomorphic, and we outline a type inference algorithm for them.

Ü6 is devoted to type inference for the conjunctive discipline. We mention some limitations to type inference here, in particular --- the fact that the set of typable expressions is not effectively decidable. Moreover, there is no feasible algorithm that would type expressions even when these are given with a quantificational typing. This kind of non-effectiveness motivates our considering a restriction to types where type conjunction is permitted only at low levels of functionality. Here the level of functionality of a function (or procedure) is recursively defined as one plus the greatest level of functionality of its arguments. This gives rise to a hierarchy on polymorphic types, a notion that is equally natural for the type abstraction and type quantification disciplines. We show that our algorithm V (of Ü3) can be naturally extended to the restriction of the conjunctive discipline to types of rank 2 in the hierarchy, and we outline an argument showing that already for a low rank, seemingly 3, type inference is not effectively decidable.

In Ü7 we discuss the ML construct let in light of our previous results. We point out that the polymorphic discipline of ML is isomorphic to the restriction to rank 2 of each one of the other disciplines. This gives weight to the particular choice of polymorphism in ML, and to the completeness of Milner's algorithm W for that choice. At the same time, the equivalence suggests more flexible representations of this discipline (namely --- either the conjunctive or the quantificational disciplines restricted to rank 2) in which the anomaly in ML, of legal expressions with well-formed illegal subexpressions, is avoided.


REFERENCES

Note: OCR errors may be found in this Reference List extracted from the full text article. ACM has opted to expose the complete List rather than only correct and linked references.

 
1
{Bar} H. P. Barendregt, The Lambda Calculus, Its Syntax and Semantics, North Holland, Amsterdam, 1981, xiv+615pp.
 
2
{BCD} H. Barendregt, M. Coppo and M. Dezani-Ciancaglini, "A filter lambda model and the completeness of type assignment," to appear in the Journal of Symbolic Logic.
 
3
{CD} M. Coppo and M. Dezani-Ciancaglini, "A new type assignment for λ-terms," Archive f. math. Logik u. Grundlagen-forschung19 (1979) 139-156.
 
4
{CDV80} M. Coppo, M. Dezani-Ciancaglini and B. Venneri, "Principal type schemes and lambda-calculus semantics," pp. 535-560 in {SH}.
 
5
{CDV81} M. Coppo, M. Dezani-Ciancaglini and B. Venneri, "Functional characters of solvable terms." Zeitschrift fur Mathematische Logik und Grundlagen der Matematik,27 (1981) 45-58.
 
6
 
7
{CF} H. B. Curry and R. Feys, Combinatory Logic, North-Holland, Amsterdam, 1958.
8
9
 
10
 
11
{Gir} J.-Y. Girard, Interpretation fonctionelle et elimination des coupures dans l'arithmetique d'ordre superieur, These de Doctorat d'Etat, 1972, Paris.
 
12
{Hin} R. Hindley, "The principal type-scheme of an object in combinatory logic," Trans. Amer. Math. Society146 (1969) 29-60.
 
13
{How} W. A. Howard, "The formula as type notion of construction," pp.479-490 in {SH}.
14
 
15
{Mar} P. Martin-Lof, "Constructive mathematics and computer programming," Proceedings of the Sixth (1979) International Congress for Logic, Methodology and Philosophy of Science, North-Holland, Amsterdam, 1979.
 
16
17
 
18
{Mil} R. Milner, "A theory of type polymorphism in programming," Journal of Computer and System Sciences 17 (1978), 348-375.
19
 
20
{Pot} G. Pottinger, "A type assignment for the strongly normalizable λ-terms," pp. 561-577 in {SH}.
 
21
{Pra} D. Prawitz, Natural Deduction, Almqvist and Wiksell, Uppsala, 1965, 113pp.
 
22
23
 
24
 
25
{SH} J. P. Seldin and J. R. Hindley (editors), To H.B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, Academic Press, London, 1980, 606pp.
 
26
{Sta} R. Statman, "Number theoretic functions computable by polymorphic programs," in Twenty Second Annual Symposium on Foundations of Computer Science, 1981, 279-282.

CITED BY  39