Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
article
Open access

Type classes in Haskell

Published: 01 March 1996 Publication History
  • Get Citation Alerts
  • Abstract

    This article defines a set of type inference rules for resolving overloading introduced by type classes, as used in the functional programming language Haskell. Programs including type classes are transformed into ones which may be typed by standard Hindley-Milner inference rules. In contrast to other work on type classes, the rules presented here relate directly to Haskell programs. An innovative aspect of this work is the use of second-order lambda calculus to record type information in the transformed program.

    References

    [1]
    AUGUSTSSON, L. 1993. Implementing Haskell overloading. In Proceedings of the 1993 Conference on Functional Programming and Computer Architecture (Copenhagen, Denmark). ACM, New York, 65-73.
    [2]
    BLOTT, S. 1991. Type classes. Ph.D. thesis, Dept. of Computing Science, Glasgow Univ., Glasgow, Scotland.
    [3]
    CARDELLI, L. 1987. Basic polymorphic typechecking. Sci. Comput. Program. 8, 147-172.
    [4]
    CHEN, I~. 1994. Semantics and coherence for parametric type classes. Res. Rep., YALEU/DCS/RR-1003, Dept. of Computer Science, Yale Univ., New Haven, Conn. June.
    [5]
    CHEN, I~. 1995. A parametric extension of Haskell's type classes. Ph.D. thesis, Dept. of Computer Science, Yale Univ., New Haven, Conn.
    [6]
    CHEN~ K., HUDAK~ P., AND ODERSKY~ M. 1992. Parametric type classes. In Proceedings of the 1992 ACM Conference on Lisp and Functional Programming. ACM, New York, 170-181.
    [7]
    CORMACK G. V. AND WRIGHT~ A. K. 1990. Type dependent parameter inference. In Proceedings of the 1990 A CM Conference on Programming Language Design and Implementation (White Plains, N.Y.), ACM. New York, 127-136.
    [8]
    GIRARD J.-Y. 1972. Interpr6tation functionelle et 61imination des coupures dans l'arithm6tique d'ordre sup6rieure. ThSse de doctorat d'6tat, Universit6 Paris VII, Paris, France.
    [9]
    HAMMOND K. 1991. Efficient type inference using monads. In 1991 Glasgow Workshop on Functional Programming (Ullapool, Scotland}. Workshops in Computing Science, Springer-Verlag, Berlin, 146-157.
    [10]
    HAMMOND~ K. 1993. Extended type classes, Int. Memo., Dept. of Computer Science, Glasgow Univ., Glasgow, Scotland.
    [11]
    HAMMOND~ K. AND BLOTT~ S. 1989. Implementing Haskell type classes. In 1989 Glasgow Workshop on Functional Programming (Fraserburgh, Scotland}. Workshops in Computing Science, Springer-Verlag, Berlin, 266-286.
    [12]
    HINDLEY~ R. 1969. The principal type scheme of an object in combinatory logic. Trans. Am. Math. Soc. 146, 29-60.
    [13]
    HUDAK~ P.~ PEYTON JONES~ S. L.~ AND WADLER~ P.L., Eds., 1992. Report on the programming language Haskell, version 1.2. ACM SIGPLAN Not. 27, 5.
    [14]
    HUET (~.~ Ed. 1990. Logical Foundations of Functional Programming. Addison-Wesley, Reading, Mass.
    [15]
    JONES, M. P. 1992a. A theory of qualified types. In Proceedings of the 1992 European Symposium on Programming (Rennes, France). Lecture Notes in Computer Science, vol. 582. Springer- Verlag, Berlin.
    [16]
    JONES M.P. 1992b. A theory of qualified types. D.Phil. thesis, Programming Research Group, Oxford Univ., Oxford, England. Published by Oxford University Press, 1994.
    [17]
    JONES M. P. 1992c. Efficient implementation of type class overloading. Int. Memo., Programming Research Group, Oxford Univ., Oxford, England.
    [18]
    JONES, M.P. 1993. Partial Evaluation for dictionary-free overloading. Res. Rep., YALEU/DCS/RR-959, Dept. of Computer Science, Yale Univ., New Haven, Conn. Apr.
    [19]
    JONES, M. P. 1994. Simplifying and improving qualified types. Res. Rep., YALEU/DCS/RR-1040, Dept. of Computer Science, Yale Univ., New Haven, Conn. June.
    [20]
    JONES~ M. P. 1995. A system of constructor classes: Overloading and implicit higher-order polymorphism. J. Func. Program. 5, 1, 1-37.
    [21]
    KAES, S. 1988. Parametric polymorphism. In Proceedings of the 1988 European Symposium on Programming (Nancy, France). Lecture Notes in Computer Science, vol. 300. Springer-Verlag, Berlin.
    [22]
    LAUFER~ K. 1992. Polymorphic type inference and abstract data types. Ph.D. thesis, New York Univ., New York.
    [23]
    LAUFER~ K. 1993. An extension of Haskell with first-class abstract types. Tech. Rep., Loyola Univ. Chicago, Ill.
    [24]
    LAUFER~ K. AND ODERSKY~ M. 1994. Polymorphic type inference and abstract data types. A CM Trans. Program. Lang. Syst. 16, 5, 1411-1430.
    [25]
    MILNER~ R. 1978. A theory of type polymorphism in programming. J. Comput. Syst. Sci. 17, 348-375.
    [26]
    MILNER~ R.~ TOFTE~ M.~ AND HARPER~ R. 1990. The Definition of Standard ML. MIT Press, Cambridge, Mass.
    [27]
    MILNER~ R. AND TOFTE~ M. 1991. Commentary on Standard ML. MIT Press, Cambridge, Mass.
    [28]
    NIPKOW~ T. AND PREHOFER~ C. 1993. Type checking type classes. In Proceedings of the 20th ACM Symposium on Principles of Programming Languages. ACM, New York, 409-418.
    [29]
    NIPKOW~ T. AND SNELTING~ G. 1991. Type classes and overloading resolution via order-sorted unification. In Proceedings of the 1991 Conference on Functional Programming Languages and Computer Architecture (Boston, Mass.). Lecture Notes in Computer Science, vol. 523. Springer- Verlag, Berlin, 1-14.
    [30]
    ODERSKY, M. AND LAUFER, K. 1991. Type classes are signatures of abstract types. Tech. Rep., IBM T.J. Watson Research Center, Yorktown Heights, N.Y. May.
    [31]
    PEYTON JONES, S. L. 1987. The Implementation of Functional Programming Languages. Prentice- Hall International, Englewood Cliffs, N.J.
    [32]
    PEYTON JONES, S.L. AND WADLER, P.L. 1991. A static semantics for Haskell. Int. Memo., Dept. of Computing Science, Glasgow Univ., Glasgow, Scotland.
    [33]
    REYNOLDS, J. C. 1974. Towards a theory of type structure. In Proceedings of the Colloque sur la Programmation. Lecture Notes in Computer Science, vol. 19. Springer-Verlag, Berlin, 408-425.
    [34]
    REYNOLDS, J. C. 1985. Three approaches to type structure. In Mathematical Foundations of Software Development. Lecture Notes in Computer Science, vol. 185. Springer-Verlag, Berlin, 97-138.
    [35]
    ROUAIX, F. 1990. Safe run-time overloading. In Proceedings of the 17th ACM Symposium on Principles of Programming Languages (San Francisco, Calif.). ACM, New York, 355-366.
    [36]
    TURNER, D. t. 1985. Miranda: A non-strict functional language with polymorphic types. In Proceedings of the 1985 Conference on Functional Programming Languages and Computer Architecture (Nancy, France). Lecture Notes in Computer Science, vol. 201. Springer-Verlag, Berlin, 1-16.
    [37]
    VOLPANO, D. M. AND SMITH, G. S. 1991. On the complexity of ML typability with overloading. In Proceedings of the 1991 Conference on Functional Programming Languages and Computer Architecture (Boston, Mass.). Lecture Notes in Computer Science, vol. 523. Springer-Verlag, Berlin, 15-28.
    [38]
    WADLER, P. L. 1992. The essence of functional programming. In Proceedings of the 19th ACM Symposium on Principles of Programming Languages (Albuquerque, N.M.). ACM, New York, 1-14.
    [39]
    WADLER, P. L. AND BLOTT, S. 1989. How to make ad-hoc polymorphism less ad hoc. In Proceedings of the 16th ACM Symposium on Principles of Programming Languages (Austin, Tex.). ACM, New York, 60-76.

    Cited By

    View all
    • (2024)Double-Ended Bit-Stealing for Algebraic Data TypesProceedings of the ACM on Programming Languages10.1145/36746288:ICFP(88-120)Online publication date: 15-Aug-2024
    • (2024)Explicit Effects and Effect Constraints in ReMLProceedings of the ACM on Programming Languages10.1145/36329218:POPL(2370-2394)Online publication date: 5-Jan-2024
    • (2024)Flexible and reversible conversion between extensible records and overloading constraints for MLJournal of Systems and Software10.1016/j.jss.2024.112141216(112141)Online publication date: Oct-2024
    • Show More Cited By

    Recommendations

    Reviews

    Christopher Martin Holt

    Type inferencing in a subset of Haskell that contains overloading (but not pattern matching) is described. The process involves adding extra parameters to overloaded functions, thus making the previously implicit typing explicit. Rules are provided for translating Haskell source into a target language (a typed lambda calculus with type abstraction and application). A type class is a parameterized type with defined operations, possibly inheriting operations from another such class. When type classes are introduced in Haskell, environments are augmented to hold information about bindings. There are environments for six different kinds of objects. The translation of an expression requires extracting information from these environments to resolve the type of the expression, which is added to the translation. I was left feeling vaguely uneasy. The outline discussing classes and instances is fine, and the translation approach as an implementation technique seems reasonable. However, computing has a long history of language features being defined by translation (for example, if-then-else defined via jumps), which can be a sign that the appropriate level of abstraction for the language feature has not yet been found. This concern was reinforced by the observation in the paper that Haskell proper has over 100 translation rules for types. Leaving that aside, the paper should be of value to language designers and high-level implementors who want to learn techniques for managing types with inheritance. As the style is not particularly readable, it would probably not be of great interest to the casual computer scientist.

    Access critical reviews of Computing literature here

    Become a reviewer for Computing Reviews.

    Comments

    Information & Contributors

    Information

    Published In

    cover image ACM Transactions on Programming Languages and Systems
    ACM Transactions on Programming Languages and Systems  Volume 18, Issue 2
    March 1996
    126 pages
    ISSN:0164-0925
    EISSN:1558-4593
    DOI:10.1145/227699
    Issue’s Table of Contents

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 01 March 1996
    Published in TOPLAS Volume 18, Issue 2

    Permissions

    Request permissions for this article.

    Check for updates

    Author Tags

    1. Haskell
    2. functional programming
    3. type classes
    4. types

    Qualifiers

    • Article

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)411
    • Downloads (Last 6 weeks)36
    Reflects downloads up to 11 Aug 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2024)Double-Ended Bit-Stealing for Algebraic Data TypesProceedings of the ACM on Programming Languages10.1145/36746288:ICFP(88-120)Online publication date: 15-Aug-2024
    • (2024)Explicit Effects and Effect Constraints in ReMLProceedings of the ACM on Programming Languages10.1145/36329218:POPL(2370-2394)Online publication date: 5-Jan-2024
    • (2024)Flexible and reversible conversion between extensible records and overloading constraints for MLJournal of Systems and Software10.1016/j.jss.2024.112141216(112141)Online publication date: Oct-2024
    • (2023)Weighted Refinement Types for Counterpoint CompositionProceedings of the 11th ACM SIGPLAN International Workshop on Functional Art, Music, Modelling, and Design10.1145/3609023.3609804(2-7)Online publication date: 30-Aug-2023
    • (2023)A type-directed, dictionary-passing translation of method overloading and structural subtyping in Featherweight Generic GoJournal of Functional Programming10.1017/S095679682300004733Online publication date: 9-Oct-2023
    • (2022)Linearly qualified types: generic inference for capabilities and uniquenessProceedings of the ACM on Programming Languages10.1145/35476266:ICFP(137-164)Online publication date: 31-Aug-2022
    • (2022)Embedded pattern matchingProceedings of the 15th ACM SIGPLAN International Haskell Symposium10.1145/3546189.3549917(123-136)Online publication date: 6-Sep-2022
    • (2022)Bridging the Gap between Different Programming Paradigms in Coverage-based Fault LocalizationProceedings of the 13th Asia-Pacific Symposium on Internetware10.1145/3545258.3545272(75-84)Online publication date: 11-Jun-2022
    • (2022)Staging with class: a specification for typed template HaskellProceedings of the ACM on Programming Languages10.1145/34987236:POPL(1-30)Online publication date: 12-Jan-2022
    • (2022)Creating a Language for Writing Real-Time Applications for the Internet of Things2022 20th ACM-IEEE International Conference on Formal Methods and Models for System Design (MEMOCODE)10.1109/MEMOCODE57689.2022.9954383(1-20)Online publication date: 13-Oct-2022
    • Show More Cited By

    View Options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Get Access

    Login options

    Full Access

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media