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:
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.
Supported by the Defense Advanced Research Projects Agency/Information Systems Technology Office under the Office of Naval Research contract N00014-90-J-1110
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
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.
L. Cardelli. Basic polymorphic typechecking. Science of Computer Programming, 9 (8): 147–172, 1987.
L. Cardelli and P. Wegner. On understanding types, data abstraction and polymorphism. ACM Computing Surveys, 17 (4): 471–522, Dec. 1985.
W. Cook. A proposal for making Eiffel type-safe. Computer Journal,32(4):305311, 1989.
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.
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.
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.
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.
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.
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.
R. Milner. A theory of type polymorphism in programming. J. Computer and System Sciences, 17: 348–375, 1978.
R. Milner, M. Tofte., and R. Harper. The Definition of Standard ML. MIT Press, 1990.
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.
J. Mitchell and G. Plotkin. Abstract Types have Existential Type. InProc. 12th ACM Symp. on Principles of Programming Languagespages 37–51. ACM, Jan. 1985.
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.
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.
D. Sandberg. An alternative to subclassing. In Proc. Object-Oriented Programming: Languages, Systems and Applications, pages 424–428, 1986.
S. Thatte. Type inference with partial types. In Proc. Intl Conf. on Algorithms, Languages and Programming, pages 615–629, 1988.
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.
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 1992 Springer-Verlag London
About this paper
Cite this paper
Läufer, K., Odersky, M. (1992). Type Classes are Signatures of Abstract Types. In: Darlington, J., Dietrich, R. (eds) Declarative Programming, Sasbachwalden 1991. Workshops in Computing. Springer, London. https://doi.org/10.1007/978-1-4471-3794-8_10
Download citation
DOI: https://doi.org/10.1007/978-1-4471-3794-8_10
Publisher Name: Springer, London
Print ISBN: 978-3-540-19735-5
Online ISBN: 978-1-4471-3794-8
eBook Packages: Springer Book Archive