[go: up one dir, main page]
More Web Proxy on the site http://driver.im/ skip to main content
article

Type inference with simple selftypes is NP-complete

Published: 01 September 1997 Publication History

Abstract

The metavariable self is fundamental in object-oriented languages. Typing self in the presence of inheritance has been studied by Abadi and Cardelli, Bruce, and others. A key concept in these developments is the notion of selftype, which enables flexible type annotations that are impossible with recursive types and subtyping. Bruce et al. demonstrated that, for the language TOOPLE, type checking is decidable. Open until now is the problem of type inference with selftype.In this paper we present a simple type system with selftype, recursive types, and subtyping, and we prove that type inference is NP-complete. With recursive types and subtyping alone, type inference is known to be P-complete. Our example language is the object calculus of Abadi and Cardelli. Both our type inference algorithm and our lower bound are the first such results for a type system with selftype.

References

[1]
{1} Martín Abadi and Luca Cardelli. A semantics of object types. In Proc. LICS'94, Ninth Annual IEEE Symposium on Logic in Computer Science, 332-341, 1994.]]
[2]
{2} Martín Abadi and Luca Cardelli. A theory of primitive objects: Second-order systems. In Proc. ESOP'94, European Symposium on Programming, 1-25. Springer-Verlag (LNCS 788), 1994.]]
[3]
{3} Martín Abadi and Luca Cardelli. A theory of primitive objects: Untyped and first-order systems. In Proc. TACS'94, Theoretical Aspects of Computing Software, 296-320. Springer-Verlag (LNCS 789), 1994.]]
[4]
{4} Martín Abadi and Luca Cardelli. An imperative object calculus. In Proc. TAPSOFT'95, Theory and Practice of Software Development, 471-485. Springer-Verlag (LNCS 915), Aarhus, Denmark, May 1995.]]
[5]
{5} Martín Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag, 1996.]]
[6]
{6} Kim B. Bruce. Safe type checking in a statically typed object-oriented programming language. In Proc. POPL'93, Twentieth Annual SIGPLAN/SIGACT Symposium on Principles of Programming Languages, 285-298, 1993.]]
[7]
{7} Kim B. Bruce, Jon Crabtree, Thomas P. Murtagh, Robert van Gent, Allyn Dimock, and Robert Muller. Safe and decidable type checking in an object-oriented language. In Proc. OOPSLA '93, ACM SIGPLAN Eighth Annual Conference on Object-Oriented Programming Systems, Languages and Applications, 29-46, 1993.]]
[8]
{8} William Cook and Jens Palsberg. A denotational semantics of inheritance and its correctness. Information and Computation, 114(2), 329-350, 1994. Preliminary version in Proc. OOPSLA'89, ACM SIGPLAN Fourth Annual Conference on Object-Oriented Programming Systems, Languages and Applications, 433-443, New Orleans, Louisiana, October 1989.]]
[9]
{9} My Hoang and John C. Mitchell. Lower bounds on type inference with subtypes. In Proc. POPL'95, 22nd Annual SIGPLAN//SIGACT Symposium on Principles of Programming Languages, 176-185, 1995.]]
[10]
{10} Bent B. Kristensen, Ole Lehrmann Madsen, Birger Møller-Pedersen, and Kristen Nygaard. The BETA programming language. In Bruce Shriver and Peter Wegner, editors, Research Directions in Object-Oriented Programming, 7-48. MIT Press, 1987.]]
[11]
{11} Bertrand Meyer. Object-Oriented Software Construction. Prentice-Hall, Englewood Cliffs, NJ, 1988.]]
[12]
{12} John C. Mitchell. Toward a typed foundation for method specialization and inheritance. In Seventeenth Symposium on Principles of Programming Languages, 109-124, 1990.]]
[13]
{13} John C. Mitchell, Furio Honsell, and Kathleen Fisher. A lambda calculus of objects and method specialization. Nordic Journal of Computing, 1(1), 537, 1994. Also in Proc. LICS'93, 26-38.]]
[14]
{14} Jens Palsberg. Efficient inference of object types. Information and Computation, 123(2), 198-209, 1995. Preliminary version in Proc. LICS'94, Ninth Annual IEEE Symposium on Logic in Computer Science, 186-195, Paris, France, July 1994.]]
[15]
{15} Jens Palsberg and Michael I. Schwartzbach. Object-Oriented Type Systems. John Wiley & Sons, 1994.]]
[16]
{16} Jens Palsberg and Michael I. Schwartzbach. Static typing for object-oriented programming. Science of Computer Programming, 23(1), 19-53, 1994.]]
[17]
{17} Jerzy Tiuryn. Subtype inequalities. In LICS'92, Seventh Annual IEEE Symposium on Logic in Computer Science, 308-315, 1992.]]
[18]
{18} Sergei Vorobyov. Structural decidable extensions of bounded quantification. In Proc. POPL'95, 22nd Annual SIGPLAN/SIGACT Symposium on Principles of Programming Languages, 1995.]]

Cited By

View all

Recommendations

Reviews

R. Clayton

Type inferencing accepts a program without explicit typing, and produces an equivalent, statically typed program in which all program entities are tagged by their type. Selftyping provides virtual return types for nonvirtual, inherited class methods. Without selftypes, an inherited method returns an instance of the method's defining class; with selftypes, the method returns an instance of the calling method's class. Selftyping eliminates the explicit downcasting that may be required when a child calls methods implemented in an ancestor. NP-complete problems are best solved by first guessing a solution, and then verifying the solution's correctness. NP completeness suggests that exact solutions are exponentially expensive, and that it may be better to consider approximate solutions that are not completely correct, but that can be computed more cheaply than an exact solution. The authors demonstrate that guessing and verifying is the best way to perform type inference on programs using selftyping. They do not speculate on approximate solutions, which, given the problem, is appropriate. They do offer the hope that type and selftyping systems less austere than the ones used in this paper may provide enough extra information to allow for more efficient type inferencing. Readers who know object-oriented languages will find enough detail in this paper to pick up type inference and selftyping. Readers must be previously familiar with complexity theory, however. In fact, an unquestioning predilection for complexity proofs will be helpful: the pragmatic and unintuitive translation between type inferencing and satisfiability will deny most of the laity the small pleasure that usually comes from seeing one problem unexpectedly and neatly transformed into another. Online Computing Reviews Service

Access critical reviews of Computing literature here

Become a reviewer for Computing Reviews.

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image Nordic Journal of Computing
Nordic Journal of Computing  Volume 4, Issue 3
Fall 1997
84 pages

Publisher

Publishing Association Nordic Journal of Computing

Finland

Publication History

Published: 01 September 1997

Author Tags

  1. constraints
  2. type inference

Qualifiers

  • Article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)0
  • Downloads (Last 6 weeks)0
Reflects downloads up to 26 Jan 2025

Other Metrics

Citations

Cited By

View all

View Options

View options

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media