Advertisement

Type Classes are Signatures of Abstract Types

  • Konstantin Läufer
  • Martin Odersky
Conference paper
Part of the Workshops in Computing book series (WORKSHOPS COMP.)

Abstract

We present an extension of Haskell’s type class concept in which a type class is identified with the signature of an abstract type As shown by Mitchell and Plotkin, abstract types can be expressed using existential quantification. Unlike in Mitchell and Plotkin’s work, an abstract type does not come with one — and only one — implementation. Rather, any concrete type can be declared to be an implementation by a clause that corresponds to an instance declaration in Haskell. We introduce F-bounded existential quantification, where an abstract type has the form:
$$\exists \alpha .C(\alpha ).\tau (\alpha ).$$
Here, C(α) is a set of constraints that restricts the range of the bound variable α, and τ(α) is a type constructed from α. The expression reads “some type τ(α), where α is some arbitrary fixed type satisfying constraints C(α)”. The constraint set C corresponds to a type class. Just like a type class, it contains declarations for overloaded identifiers as well as conformity clauses that declare one abstract type to be more specific than another.

The generalization of type classes to abstract types has the advantage of greater expressiveness: We can model polymorphic abstract types and heterogeneous data structures, concepts which cannot be expressed in Haskell. An example of a polymorphic abstract type is ∀α.Bag α, the abstract type of all bags with elements of type α. In Haskell, we would either have to fix the element type, or we would have to fix the implementation of Bag.

Our extension shares the desirable properties of the type class approach in that it is fully static and in that type reconstruction is feasible.

Keywords

Type Class Type Inference Existential Quantifier Concrete Type Abstract Type 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. [1]
    P. Canning, W. Cook, W. Hill, W. Olthoff, and J. Mitchell. F-bounded polymorphism for object-oriented programming. In Proc. Functional Programming and Computer Architecture, pages 273–280, 1989.Google Scholar
  2. [2]
    L. Cardelli. Basic polymorphic typechecking. Science of Computer Programming, 9 (8): 147–172, 1987.CrossRefGoogle Scholar
  3. [3]
    L. Cardelli and P. Wegner. On understanding types, data abstraction and polymorphism. ACM Computing Surveys, 17 (4): 471–522, Dec. 1985.Google Scholar
  4. [4]
    W. Cook. A proposal for making Eiffel type-safe. Computer Journal,32(4):305311, 1989.Google Scholar
  5. [5]
    G. Cormack and A. Wright. Type-dependent parameter inference. In Proc. SIGPLAN’90 Conf. on Programming Language Design and Implementation, pages 127–136, White Plains, NY, June 1990.Google Scholar
  6. [6]
    L. Damas and R. Milner. Principal type schemes for functional programs. In Proc. 9th Annual ACM Symp. on Principles of Programming Languages, pages 207–212, Jan. 1982.Google Scholar
  7. [7]
    F. Henglein and H. Mairson. The complexity of type inference for higher-order typed lambda calculi. In Proc. 18th ACM Symp. on Principles of Programming Languages (POPL), Orlando, Florida, Jan. 1991.Google Scholar
  8. [8]
    S. Kaes. Parametric overloading in polymorphic programming languages. In H. Ganzinger, editor, Proc. 2nd European Symosium on Programming, Lecture Notes in Computer Science, Vol. 300, pages 131–144, Nancy, France, March 1988. Springer-Verlag.Google Scholar
  9. [9]
    K. Läufer and M. Odersky. Type inference for an object-oriented extension of ML. NYU-CIMS Report, New York University, Department of Computer Science, in preparation.Google Scholar
  10. [10]
    D. MacQueen. Using dependent types to express modular structure. In Proc. 13th ACM Symp. on Principles of Programming Languages, pages 277–286. ACM, Jan. 1986.Google Scholar
  11. [11]
    R. Milner. A theory of type polymorphism in programming. J. Computer and System Sciences, 17: 348–375, 1978.MATHMathSciNetCrossRefGoogle Scholar
  12. [12]
    R. Milner, M. Tofte., and R. Harper. The Definition of Standard ML. MIT Press, 1990.Google Scholar
  13. [13]
    J. Mitchell, S. Meldal, and N. Madhay. An extension of Standard ML modules with subtyping and inheritance. In Proc. ACM Symp. on Principles of Programming LanguagesJan. 1991. Google Scholar
  14. [14]
    J. Mitchell and G. Plotkin. Abstract Types have Existential Type. InProc. 12th ACM Symp. on Principles of Programming Languagespages 37–51. ACM, Jan. 1985. Google Scholar
  15. [15]
    T. Niphow and G. Snelting. Type classes and overloading resolution via order-sorted unification. Technical Report PI-R8/90, Technische Hochschule Darmstadt, Praktische Informatik, July 1990.Google Scholar
  16. [16]
    J. Palsberg and M. Schwartzbach. Type substitution for object-oriented programming. In N. Meyrowitz, editor,Proc. Conf. Object-Oriented Programming: Systems Languages and Applications and European Conf. on Object-Oriented Programmingpages 151–160, Ottawa, Canada, Oct. 1990. ACM Press. Google Scholar
  17. [17]
    D. Sandberg. An alternative to subclassing. In Proc. Object-Oriented Programming: Languages, Systems and Applications, pages 424–428, 1986.Google Scholar
  18. [18]
    S. Thatte. Type inference with partial types. In Proc. Intl Conf. on Algorithms, Languages and Programming, pages 615–629, 1988.Google Scholar
  19. [19]
    P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad hoc. In Proc. 16th Annual ACM Symp. on Principles of Programming Languages,pages 6076. ACM, Jan. 1989.Google Scholar

Copyright information

© Springer-Verlag London 1992

Authors and Affiliations

  • Konstantin Läufer
    • 1
  • Martin Odersky
    • 2
  1. 1.New York UniversityNew YorkUSA
  2. 2.IBM T.J. Watson Research CenterYorktown HeightsUSA

Personalised recommendations