Subtypes vs. where clauses: constraining parametric polymorphism

  • Authors:
  • Mark Day;Robert Gruber;Barbara Liskov;Andrew C. Myers

  • Affiliations:
  • Lotus Development Corporation, 1 Rogers Street, Cambridge, MA;Laboratory for Computer Science, Massachusetts Institute of Technology, 545 Technology Square, Cambridge, MA;Laboratory for Computer Science, Massachusetts Institute of Technology, 545 Technology Square, Cambridge, MA;Laboratory for Computer Science, Massachusetts Institute of Technology, 545 Technology Square, Cambridge, MA

  • Venue:
  • Proceedings of the tenth annual conference on Object-oriented programming systems, languages, and applications
  • Year:
  • 1995

Quantified Score

Hi-index 0.00

Visualization

Abstract

All object-oriented languages provide support for subtype polymorphism, which allows the writing of generic code that works for families of related types. There is also a need, however, to write code that is generic across types that have no real family relationship. To satisfy this need a programming language must provide a mechanism for parametric polymorphism, allowing for types as parameters to routines and types. We show that to support modular programming and separate compilation there must be a mechanism for constraining the actual parameters of the routine or type. We describe a simple and powerful constraint mechanism and compare it with constraint mechanisms in other languages in terms of both ease of use and semantic expressiveness. We also discuss the interaction between subtype and parametric polymorphism: we discuss the subtype relations that can exist between instantiations of parameterized types, and which of those relations are useful and can be implemented efficiently. We illustrate our points using examples in Theta, a new object-oriented language, and we describe the time- and space-efficient implementation of parametric polymorphism used in Theta.