skip to main content
article
Open Access

A theory of overloading

Published:01 November 2005Publication History
Skip Abstract Section

Abstract

We present a novel approach to allow for overloading of identifiers in the spirit of type classes. Our approach relies on a combination of the HM(X) type system framework with Constraint Handling Rules (CHRs). CHRs are a declarative language for writing incremental constraint solvers, that provide our scheme with a form of programmable type language. CHRs allow us to precisely describe the relationships among overloaded identifiers. Under some sufficient conditions on the CHRs we achieve decidable type inference and the semantic meaning of programs is unambiguous. Our approach provides a common formal basis for many type class extensions such as multiparameter type classes and functional dependencies.

References

  1. Abdennadher, S. 1997. Operational semantics and confluence of constraint propagation rules. In Proceedings of the 3rd International Conference on Principles and Practice of Constraint Programming, CP'97. Lecture Notes in Computer Science, Springer-Verlag, New York, 252--266.]]Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Abdennadher, S. and Frühwirth, T. 1998. On completion of constraint handling rules. In Proceedings of the 4th International Conference on Principles and Practice of Constraint Programming (CP98). Lecture Notes in Computer Science, vol. 1520. Springer-Verlag, New York, 25--39.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Abdennadher, S. and Schütz, H. 1998. CHRˇ : A flexible query language. In Proceedings of Flexible Query Answering Systems. Lecture Notes in Artificial Intelligence, vol. 1495. Springer-Verlag, New York, 1--14.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Augustsson, L. 1998. Cayenne---A language with dependent types. In Proceedings of the International Conference on Functional Programming (ICFP 1998). 239--250.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Breazu-Tannen, V., Gunter, C. A., and Scedrov, A. 1990. Computing with coercions. In Proceedings of the Conference on LISP and Functional Programming (Nice, France) ACM, New York, 44--60.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Camarao, C. and Figueiredo, L. 1999. Type inference for overloading without restrictions, declarations or annotations. In Proceedings of the 4th Fuji International Symposium on Functional and Logic Programming. Lecture Notes in Computer Science, vol. 1722, Springer-Verlag, New York, 37--52.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Chen, K., Hudak, P., and Odersky, M. 1992. Parametric type classes. In Proceedings of the ACM Conference on LISP and Functional Programming. ACM, New York, 170--191.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Demoen, B., García de la Banda, M., Harvey, W., Marriott, K., and Stuckey, P. 1999. An overview of HAL. In Proceedings of the 4th International Conference on Principles and Practices of Constraint Programming. Lecture Notes in Computer Science, Springer-Verlag, New York, 174--188.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Duggan, D. and Ophel, J. 2002a. Open and closed scopes for constrained genericity. Theoret. Comput. Sci. 275, 1--2, 215--258.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Duggan, D. and Ophel, J. 2002b. Type-checking multi-parameter type classes. J. Funct. Prog. 12, 2, 133--158.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Fridlender, D. and Indrika, M. 2000. Do we need dependent types? J. Funct. Prog. 10, 4, 409--415.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Frühwirth, T. 1995. Constraint handling rules. In Constraint Programming: Basics and Trends. Lecture Notes in Computer Science, vol. 910. Springer-Verlag, NewYork.]]Google ScholarGoogle Scholar
  13. Frühwirth, T. 1998a. A declarative language for constraint systems: Habilitation. Institut für Informatik, Ludwig-Maximilians-University Munich, Germany, July.]]Google ScholarGoogle Scholar
  14. Frühwirth, T. 1998b. Theory and practice of constraint handling rules. J. Logic Prog. 37, 1--3, 95--138.]]Google ScholarGoogle ScholarCross RefCross Ref
  15. Gasbichler, M., Neubauer, M., Sperber, M., and Thiemann, P. 2002. Functional logic overloading. In Proceedings of the 29th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Portland, OR). ACM, New York, 233--244.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. GHC 2003. Glasgow Haskell Compiler Home Page. http://www.haskell.org/ghc/.]]Google ScholarGoogle Scholar
  17. Glynn, K., Stuckey, P., and Sulzmann, M. 2000. Type classes and constraint handling rules. In Proceedings of the 1st Workshop on Rule-Based Constraint Reasoning and Programming.]]Google ScholarGoogle Scholar
  18. Hanus, M. 1994. The integration of functions into logic programming: From theory to practice. J. Logic Prog. 19&20, 583--628.]]Google ScholarGoogle Scholar
  19. Henglein, F. 1993. Type inference with polymorphic recursion. Trans. Prog. Lang. Syst. 15, 1 (April), 253--289.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Jeffery, D., Henderson, F., and Somogyi, Z. 2000. Type classes in Mercury. In Proceedings of the 23rd Australasian Computer Science Conference. Australian Computer Science Communications, vol. 22. IEEE Computer Society Press, Los Alamitos, CA, 128--135.]]Google ScholarGoogle Scholar
  21. Jones, M. P. 1992. Qualified types: Theory and practice. Ph.D. dissertation, Oxford University.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Jones, M. P. 1993a. Coherence for qualified types. Research Report YALEU/DCS/RR-989, Yale University, Department of Computer Science. September.]]Google ScholarGoogle Scholar
  23. Jones, M. P. 1993b. A system of constructor classes: Overloading and implicit higher-order polymorphism. In FPCA '93: Proceedings of the Conference on Functional Programming Languages and Computer Architecture. ACM, New York, 52--61.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Jones, M. P. 2000. Type classes with functional dependencies. In Proceedings of the 9th European Symposium on Programming Languages and Systems, ESOP 2000. Lecture Notes in Computer Science, vol. 1782, Springer-Verlag, New York.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Jones, S. P., Jones, M. P., and Meijer, E. 1997. Type classes: An exploration of the design space. In Haskell Workshop.]]Google ScholarGoogle Scholar
  26. Kaes, S. 1988. Parametric overloading in polymorphic programming languages. In ESOP'88. In Proceedings of the Programming Languages and Systems. Lecture Notes in Computer Science, vol. 300. Springer-Verlag, New York, 131--141.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Lewis, J., Shields, M., Meijer, E., and Launchbury, J. 2000. Implicit parameters: Dynamic scoping with static types. In Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Boston, MA). ACM, New York, 108--118.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Milner, R. 1978. A theory of type polymorphism in programming. J. Comput. Syst. Sci. 17, 348--375.]]Google ScholarGoogle ScholarCross RefCross Ref
  29. Nipkow, T. and Prehofer, C. 1995. Type reconstruction for type classes. J. Funct. Prog. 5, 2, 201--224.]]Google ScholarGoogle ScholarCross RefCross Ref
  30. Odersky, M., Sulzmann, M., and Wehr, M. 1999. Type inference with constrained types. Theory Pract. Obj. Syst. 5, 1, 35--55.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Odersky, M., Wadler, P., and Wehr, M. 1995. A second look at overloading. In Proceedings of the 7th International Conference on Functional Programming Languages and Computer Architecture (FPCA'95) (La Jolla, CA). ACM, New York, 135--146.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Peyton Jones, S. 2003. Haskell 98 Language and Libraries: the Revised Report. Cambridge University Press. (Also see http://www.haskell.org/definition/.)]]Google ScholarGoogle Scholar
  33. Plasmeijer, M. and van Eekelen, M. 1998. Language report Concurrent Clean. Tech. Rep. CSI-R9816, Computing Science Institute, University of Nijmegen, Nijmegen, The Netherlands. June. ftp://ftp.cs.kun.nl/pub/Clean/Clean13/doc/refman13.ps.gz.]]Google ScholarGoogle Scholar
  34. Shields, M. and Jones, S. P. 2001. Object-oriented overloading for Haskell. In Proceedings of the Workshop on Multi-Language Infrastructure and Interoperability.]]Google ScholarGoogle Scholar
  35. Shoenfield, J. 1967. Mathematical Logic. Addison-Wesley, Reading, MA.]]Google ScholarGoogle Scholar
  36. Somogyi, Z., Henderson, F., and Conway, T. 1996. The execution algorithms of Mercury: An efficient purely declarativelogic programming language. J. Logic Prog. 29, 1--3, 17--64.]]Google ScholarGoogle ScholarCross RefCross Ref
  37. Stuckey, P. J. and Sulzmann, M. 2002. A theory of overloading. In Proceedings of ICFP'02. 167--178.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Sulzmann, M. 2000. A general framework for Hindley/Milner type systems with constraints. Ph.D. dissertation, Yale University.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Sulzmann, M. and Wazny, J. 2003. The Chameleon system. http://www.comp.nus.edu.sg/~sulzmann/chameleon.]]Google ScholarGoogle Scholar
  40. Wadler, P. 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 (POPL). ACM, New York, 60--76.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Yang, Z. 1998. Encoding types in ML-like languages. In Proceedings of ACM SIGPLAN International Conference on Functional Programming. ACM, New York, 289--300.]] Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A theory of overloading

        Recommendations

        Reviews

        Dachuan Yu

        Overloading, also know as ad hoc polymorphism, is a powerful programming feature that allows one named function to be dispatched to different implementations based on the argument types. For instance, a "+" operator could be overloaded to work not only on integers as addition, but also on strings as concatenation. In general, overloading is useful when one wishes to define a function on multiple argument types with specialized implementations. This contrasts with parametric polymorphism, where a function is written generically to work for arguments of all types. Overloading has been studied in the context of the Hindley/Milner system, and, in particular, in the style of Haskell type classes. This paper proposes a general framework for overloading based on user-definable constraint handling rules (CHRs), and provides a common foundation for handling many previous systems in the area. It identifies some sufficient conditions on the CHRs for achieving decidable type inference and coherent semantic meaning of programs, and presents a complete type inference algorithm and a semantic meaning to programs under these CHRs. The ideas have been implemented as part of the Chameleon system. This paper mainly targets programming language theorists, and provides a novel approach and formal basis for understanding and enhancing overloading in the spirit of type classes. It also sheds light on encoding logic programs in the type language of type class systems. Although substantial background in the area is needed to appreciate the complete details, intermediate readers will benefit, with the help of a series of examples given throughout the paper. Online Computing Reviews Service

        Access critical reviews of Computing literature here

        Become a reviewer for Computing Reviews.

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        • Published in

          cover image ACM Transactions on Programming Languages and Systems
          ACM Transactions on Programming Languages and Systems  Volume 27, Issue 6
          November 2005
          347 pages
          ISSN:0164-0925
          EISSN:1558-4593
          DOI:10.1145/1108970
          Issue’s Table of Contents

          Copyright © 2005 ACM

          Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 1 November 2005
          Published in toplas Volume 27, Issue 6

          Permissions

          Request permissions about this article.

          Request Permissions

          Check for updates

          Qualifiers

          • article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader