skip to main content
research-article

The implicit calculus: a new foundation for generic programming

Published:11 June 2012Publication History
Skip Abstract Section

Abstract

Generic programming (GP) is an increasingly important trend in programming languages. Well-known GP mechanisms, such as type classes and the C++0x concepts proposal, usually combine two features: 1) a special type of interfaces; and 2) implicit instantiation of implementations of those interfaces.

Scala implicits are a GP language mechanism, inspired by type classes, that break with the tradition of coupling implicit instantiation with a special type of interface. Instead, implicits provide only implicit instantiation, which is generalized to work for any types. This turns out to be quite powerful and useful to address many limitations that show up in other GP mechanisms.

This paper synthesizes the key ideas of implicits formally in a minimal and general core calculus called the implicit calculus (λ⇒), and it shows how to build source languages supporting implicit instantiation on top of it. A novelty of the calculus is its support for partial resolution and higher-order rules (a feature that has been proposed before, but was never formalized or implemented). Ultimately, the implicit calculus provides a formal model of implicits, which can be used by language designers to study and inform implementations of similar mechanisms in their own languages.

References

  1. The Boost C++ libraries. http://www.boost.org/, 2010.Google ScholarGoogle Scholar
  2. C. Camarão and L. Figueiredo. Type inference for overloading without restrictions, declarations or annotations. In FLOPS, 1999.Google ScholarGoogle ScholarCross RefCross Ref
  3. M. Chakravarty, G. Keller, and S. L. Peyton Jones. Associated type synonyms. In ICFP, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. M. Chakravarty, G. Keller, S. L. Peyton Jones, and S. Marlow. Associated types with class. In POPL, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. D. Devriese and F. Piessens. On the bright side of type classes: Instance arguments in agda. In ICFP, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. A. Dijkstra and S. D. Swierstra. Making implicit parameters explicit. Technical report, Utrecht University, 2005.Google ScholarGoogle Scholar
  7. G. Dos Reis and B. Stroustrup. Specifying C++ concepts. In POPL '06, pages 295--308, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. D. Dreyer, R. Harper, M. Chakravarty, and G. Keller. Modular type classes. In POPL, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. R. Garcia, J. Jarvi, A. Lumsdaine, Jeremy Siek, and J. Willcock. A comparative study of language support for generic programming. In OOPSLA, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J. Gibbons. Patterns in datatype-generic programming. In The Fun of Programming, Cornerstones in Computing. Palgrave, 2003.Google ScholarGoogle Scholar
  11. D. Gregor, J. Järvi, J. G. Siek, B. Stroustrup, G. Dos Reis, and A. Lumsdaine. Concepts: linguistic support for generic programming in c++. In OOPSLA, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. R. Hinze and S. L. Peyton Jones. Derivable type classes. Electronic Notes in Theoretical Computer Science, 41(1):5--35, 2001.Google ScholarGoogle ScholarCross RefCross Ref
  13. J. Hughes. Restricted data types in Haskell. In Haskell, 1999.Google ScholarGoogle Scholar
  14. P. Jansson and J. Jeuring. Polytypic programming. In AFP. Springer-Verlag, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. M. P. Jones. Simplifying and improving qualified types. In FPCA, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. M. P. Jones. Type classes with functional dependencies. In ESOP, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. S. L. Peyton Jones, M. P. Jones, and E. Meijer. Type classes: exploring the design space. In Haskell Workshop, 1997.Google ScholarGoogle Scholar
  18. W. Kahl and J. Scheffczyk. Named instances for Haskell type classes. In Haskell Workshop, 2001.Google ScholarGoogle Scholar
  19. R. Kowalski. Predicate logic as a programming language. In Proceedings of IFIP Congress, 1974.Google ScholarGoogle Scholar
  20. R. Kowalski, Donald, and Kuehner. Linear resolution with selection function. Artificial Intelligence, 2, 1971.Google ScholarGoogle Scholar
  21. R. Lämmel and S. L. Peyton Jones. Scrap your boilerplate with class: extensible generic functions. In ICFP, 2005.Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. J. Lewis, J. Launchbury, E. Meijer, and M. Shields. Implicit parameters: dynamic scoping with static types. In POPL, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. D. Musser and A. Stepanov. Generic programming. In Symbolic and algebraic computation: ISSAC 88, pages 13--25. Springer, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. D. R. Musser and A. Saini. The STL Tutorial and Reference Guide: C++ Programming with the Standard Template Library. Addison Wesley Longman Publishing Co., Inc., 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. M. Neubauer, P. Thiemann, M. Gasbichler, and M. Sperber. Functional logic overloading. In POPL, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. M. Odersky. Poor man's type classes. http://lamp.epfl.ch/ odersky/talks/wg2.8-boston06.pdf, July 2006.Google ScholarGoogle Scholar
  27. M. Odersky. The Scala language specification, version 2.8 2010.Google ScholarGoogle Scholar
  28. B. C. d. S. Oliveira and J. Gibbons. Scala for generic programmers. Journal of Functional Programming, 20, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. B. C. d. S. Oliveira, A. Moors, and M. Odersky. Type classes as objects and implicits. In OOPSLA, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. B. C. d. S. Oliveira, T. Schrijvers, W. Choi, W. Lee, and K. Yi. Extended report: The implicit calculus. http://arxiv.org/abs/1203.4499, 2012.Google ScholarGoogle Scholar
  31. A. Rodriguez, J. Jeuring, P. Jansson, A. Gerdes, O. Kiselyov, and B. C. d. S. Oliveira. Comparing libraries for generic programming in haskell. In Haskell, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. T. Schrijvers, S. L. Peyton Jones, M. Chakravarty, and M. Sulzmann. Type checking with open type functions. In ICFP, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. T. Schrijvers, S. L. Peyton Jones, M. Sulzmann, and D. Vytiniotis. Complete and decidable type inference for GADTs. In ICFP, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. J. Siek. The C++0x Concepts Effort. http://ecee.colorado. edu/~siek/concepts_effort.pdf, 2011.Google ScholarGoogle Scholar
  35. J. G. Siek and A. Lumsdaine. Essential language support for generic programming. In PLDI, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. J. G. Siek and A. Lumsdaine. A language for generic programming in the large. Science of Computer Programming, 76(5), 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. M. Sozeau and N. Oury. First-class type classes. In TPHOLs, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. B. Stroustrup. Simplifying the use of concepts. Technical report, Technical Report N2906, ISO/IEC JTC 1 SC22 WG21, 2009.Google ScholarGoogle Scholar
  39. P. J. Stuckey and M. Sulzmann. A theory of overloading. In ICFP, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. V. Trifonov. Simulating quantified class constraints. In Haskell, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. D. Vytiniotis, S. L. Peyton Jones, T. Schrijvers, and M. Sulzmann. OUTSIDEIN(x): Modular type inference with local assumptions. Journal of Functional Programming, 21(4--5):333--412, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. P. L.Wadler and S. Blott. How to make ad-hoc polymorphism less ad hoc. In POPL, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. The implicit calculus: a new foundation for generic programming

        Recommendations

        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 SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 47, Issue 6
          PLDI '12
          June 2012
          534 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2345156
          Issue’s Table of Contents
          • cover image ACM Conferences
            PLDI '12: Proceedings of the 33rd ACM SIGPLAN Conference on Programming Language Design and Implementation
            June 2012
            572 pages
            ISBN:9781450312059
            DOI:10.1145/2254064

          Copyright © 2012 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 11 June 2012

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!