We study the complexity of type inference for programming languages with subtypes. There are three language variations that effect the problem: (i) basic functions may have polymorphic or more limited types, (ii) the subtype hierarchy may be fixed or vary as a result of subtype declarations within a program, and (iii) the subtype hierarchy may be an arbitrary partial order or may have a more restricted form, such as a tree or lattice. The naive algorithm for infering a most general polymorphic type, undervariable subtype hypotheses, requires deterministic exponential time. If we fix the subtype ordering, this upper bound grows to nondeterministic exponential time. We show that it is NP-hard to decide whether a lambda term has a type with respect to a fixed subtype hierarchy (involving only atomic type names). This lower bound applies to monomorphic or polymorphic languages. We give PSPACE upper bounds for deciding polymorphic typability if the subtype hierarchy has a lattice structure or the subtype hierarchy varies arbitrarily. We also give a polynomial time algorithm for the limited case where there are of no function constants and the type hierarchy is either variable or any fixed lattice.
[1]
Mike Paterson,et al.
Linear unification
,
1976,
STOC '76.
[2]
簡聰富,et al.
物件導向軟體之架構(Object-Oriented Software Construction)探討
,
1989
.
[3]
Harry G. Mairson,et al.
Unification and ML-Type Reconstruction
,
1991,
Computational Logic - Essays in Honor of Alan Robinson.
[4]
John C. Mitchell,et al.
Type inference with simple subtypes
,
1991,
Journal of Functional Programming.
[5]
Ryan Stansifer,et al.
Type inference with subtypes
,
1988,
POPL '88.
[6]
John C. Mitchell,et al.
Coercion and type inference
,
1984,
POPL.
[7]
Bjarne Stroustrup,et al.
C++ Programming Language
,
1986,
IEEE Softw..
[8]
John C. Mitchell,et al.
ML with extended pattern matching and subtypes
,
1988,
LISP and Functional Programming.
[9]
J. Roger Hindley,et al.
BCK-Combinators and Linear lambda-Terms have Types
,
1989,
Theor. Comput. Sci..
[10]
Prateek Mishra,et al.
Type Inference with Subtypes
,
1990,
Theor. Comput. Sci..
[11]
Mitchell Wand,et al.
On the complexity of type inference with coercion
,
1989,
FPCA.