skip to main content
research-article

Type classes as objects and implicits

Published:17 October 2010Publication History
Skip Abstract Section

Abstract

Type classes were originally developed in Haskell as a disciplined alternative to ad-hoc polymorphism. Type classes have been shown to provide a type-safe solution to important challenges in software engineering and programming languages such as, for example, retroactive extension of programs. They are also recognized as a good mechanism for concept-based generic programming and, more recently, have evolved into a mechanism for type-level computation.

This paper presents a lightweight approach to type classes in object-oriented (OO) languages with generics using the CONCEPT pattern and implicits (a type-directed implicit parameter passing mechanism). This paper also shows how Scala's type system conspires with implicits to enable, and even surpass, many common extensions of the Haskell type class system, making Scala ideally suited for generic programming in the large.

References

  1. }}J. P. Bernardy, P. Jansson, M. Zalewski, S. Schupp, and A. Priesnitz. A comparison of C++ concepts and Haskell type classes. In WGP '08, pages 37--48, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. }}Boost. The Boost C++ libraries. http://www.boost.org/, 2010.Google ScholarGoogle Scholar
  3. }}K. Bruce, L. Cardelli, G. Castagna, G. T. Leavens, and B. Pierce. On binary methods. Theor. Pract. Object Syst., 1(3):221--242, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. }}P. Canning, W. Cook, W. Hill, W. Olthoff, and J. C. Mitchell. Fbounded polymorphism for object-oriented programming. In FPCA '89, pages 273--280, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. }}M. Chakravarty, G. Keller, S. Peyton Jones, and S. Marlow. Associated types with class. pages 1--13, 2005a.Google ScholarGoogle Scholar
  6. }}M. Chakravarty, G. Keller, and Simon Peyton Jones. Associated type synonyms. In ICFP '05, pages 241--253, 2005b. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. }}C. Chambers and G. T. Leavens. Typechecking and modules for multimethods. ACM Transactions on Programming Languages and Systems, 17(6):805--843, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. }}C. Clifton, G. T. Leavens, C. Chambers, and T. Millstein. MultiJava: modular open classes and symmetric multiple dispatch for Java. In OOPSLA '00, pages 130--145, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. }}W. R. Cook. On understanding data abstraction, revisited. SIGPLAN Not., 44(10):557--572, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. }}W. R. Cook and J. Palsberg. A denotational semantics of inheritance and its correctness. Inf. Comput., 114(2):329--350, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. }}O. Danvy. Functional unparsing. J. Funct. Program., 8(6):621-- 625, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. }}A. Dijkstra and S. D. Swierstra. Making implicit parameters explicit. Technical report, Institute of Information and Computing Sciences, Utrecht University, 2005. URL http://www.cs.uu.nl/research/techreps/UU-CS-2005-032.html.Google ScholarGoogle Scholar
  13. }}G. Dos Reis and B. Stroustrup. Specifying C++ concepts. In POPL '06, pages 295--308, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. }}I. Dragos and M. Odersky. Compiling generics through userdirected type specialization. In ICOOOLPS '09, pages 42--47, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. }}D. Dreyer, R. Harper, M. M. T. Chakravarty, and G. Keller. Modular type classes. In POPL '07, pages 63--70, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. }}B. Emir, A. Kennedy, C. V. Russo, and D. Yu. Variance and generalized constraints for C# generics. In ECOOP, pages 279--303, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. }}R. Garcia, J. Jarvi, A. Lumsdaine, J. Siek, and J. Willcock. An extended comparative study of language support for generic programming. J. Funct. Program., 17(2):145--205, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. }}J. Gibbons. Patterns in datatype-generic programming. In The Fun of Programming, Cornerstones in Computing, pages 41--60. Palgrave, 2003.Google ScholarGoogle Scholar
  19. }}D. Gregor, J. Jarvi, J. Siek, B. Stroustrup, G. Dos Reis, and a A. Lumsdaine. Concepts: linguistic support for generic programming in C++. In OOPSLA '06, pages 291--310, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. }}F. Haftmann and M. Wenzel. Constructive type classes in Isabelle. In TYPES, pages 160--174, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. }}C. V. Hall, K. Hammond, S. Peyton Jones, and P. Wadler. Type classes in Haskell. ACM Trans. Program. Lang. Syst., 18(2): 109--138, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. }}K. Honda. Types for dynamic interaction. In CONCUR '93, pages 509--523, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. }}J. Hughes. Restricted data types in Haskell. In Haskell Workshop, 1999.Google ScholarGoogle Scholar
  24. }}J. Jarvi, A. Lumsdaine, J. Siek, and J. Willcock. An analysis of constrained polymorphism for generic programming. In MPOOL '03, page 87--107, 2003.Google ScholarGoogle Scholar
  25. }}M. P. Jones. Type classes with functional dependencies. In ESOP '00, pages 230--244, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. }}W. Kahl and J. Scheffczyk. Named instances for Haskell type classes. In Haskell Workshop, 2001.Google ScholarGoogle Scholar
  27. }}A. Kennedy and C. V. Russo. Generalized algebraic data types and object-oriented programming. OOPSLA '05, pages 21--40, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. }}O. Kiselyov, R. Lammel, and K. Schupke. Strongly typed heterogeneous collections. In Haskell '04, pages 96--107, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. }}O. Kiselyov, S. Peyton Jones, and C. Shan. Fun with type functions, 2009. URL http://research.microsoft.com/en-us/um/ people/simonpj/papers/assoc-types/.Google ScholarGoogle Scholar
  30. }}R. Lammel and S. P. Jones. Scrap your boilerplate with class: a extensible generic functions. In ICFP '05, pages 204--215, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. }}R. Lammel and K. Ostermann. Software extension and integration a with type classes. In GPCE '06, pages 161--170, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. }}D. B. MacQueen. Modules for Standard ML. In LISP and Functional Programming, pages 198--207, 1984. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. }}C. McBride. Faking it: Simulating dependent types in Haskell. J. Funct. Program., 12(5):375--392, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. }}J. C. Mitchell and G. D. Plotkin. Abstract types have existential type. ACM Trans. Program. Lang. Syst., 10(3):470--502, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. }}A. Moors, F. Piessens, and M. Odersky. Generics of a higher kind. In OOPSLA '08, pages 423--438, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. }}D. Musser and A. A. Stepanov. Generic programming. In Symbolic and algebraic computation: ISSAC 88, pages 13--25. Springer, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. }}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., Redwood City, CA, USA, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. }}M. Odersky, 2006. URL http://www.artima.com/weblogs/ viewpost.jsp?thread=179766.Google ScholarGoogle Scholar
  39. }}M. Odersky. The Scala Language Specification, Version 2.8. EPFL, 2010. URL http://www.scala-lang.org/docu/files/ ScalaReference.pdf.Google ScholarGoogle Scholar
  40. }}M. Odersky and A. Moors. Fighting bit rot with types (experience report: Scala collections). In FSTTCS, pages 427--451, 2009.Google ScholarGoogle Scholar
  41. }}M. Odersky, V. Cremet, C. Rockl, and M. Zenger. A nominal theory of objects with dependent types. In ECOOP03, pages 201--224. Springer-Verlag, 2003.Google ScholarGoogle ScholarCross RefCross Ref
  42. }}M. Odersky, P. Altherr, V. Cremet, I. Dragos, G. Dubochet, B. Emir, S. McDirmid, S. Micheloud, N. Mihaylov, M. Schinz, L. Spoon, E. Stenman, and M. Zenger. An Overview of the Scala Programming Language (2. edition). Technical report, EPFL, 2006.Google ScholarGoogle Scholar
  43. }}B. C. d. S. Oliveira and J. Gibbons. Scala for generic programmers. In WGP '08, pages 25--36, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. }}B. C. d. S. Oliveira and M. Sulzmann. Objects to unify type classes and GADTs. April 2008. URL http://www.comlab.ox.ac.uk/people/Bruno.Oliveira/objects.pdf.Google ScholarGoogle Scholar
  45. }}D. Orchard and T. Schrijvers. Haskell type constraints unleashed. In FLOPS '10. Springer-Verlag, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. }}S. Peyton Jones, editor. Haskell 98 Language and Libraries - The Revised Report. Cambridge University Press, Cambridge, England, 2003.Google ScholarGoogle Scholar
  47. }}S. Peyton Jones, M. Jones, and E. Meijer. Type classes: exploring the design space. In Haskell Workshop, 1997.Google ScholarGoogle Scholar
  48. }}S. Peyton Jones, D. Vytiniotis, S. Weirich, and G. Washburn. Simple unification-based type inference for GADTs. In ICFP '06, pages 50--61, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. }}S. Peyton Jones, S. Marlow, et al. The Glasgow Haskell Compiler, 2009. URL http://www.haskell.org/ghc/.Google ScholarGoogle Scholar
  50. }}T. Schrijvers, S. Peyton Jones, M. Chakravarty, and M. Sulzmann. Type checking with open type functions. In ICFP '08, pages 51--62, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. }}J. S. Shapiro, S. Sridhar, and M. S. Doerrie. BitC language specification, 2008. URL http://www.coyotos.org/docs/bitc/ spec.html.Google ScholarGoogle Scholar
  52. }}J. G. Siek and A. Lumsdaine. Essential language support for generic programming. In PLDI '05, pages 73--84, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. }}J. G. Siek and A. Lumsdaine. A language for generic programming in the large. Science of Computer Programming, In Press, Corrected Proof, 2008. URL http://www.sciencedirect.com/science/article/B6V17-4TJ6F7D-1/2/ 7d624b842e8dd84e792995d3422aee21. Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. }}M. Sozeau and N. Oury. First-class type classes. In TPHOLs '08, pages 278--293, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. }}P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad hoc. In POPL '89, pages 60--76, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. }}S. Wehr. JavaGI: A Language with Generalized Interfaces. PhD thesis, University of Freiburg, Department of Computer Science, December 2009.Google ScholarGoogle Scholar

Index Terms

  1. Type classes as objects and implicits

      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 45, Issue 10
        OOPSLA '10
        October 2010
        957 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/1932682
        Issue’s Table of Contents
        • cover image ACM Conferences
          OOPSLA '10: Proceedings of the ACM international conference on Object oriented programming systems languages and applications
          October 2010
          984 pages
          ISBN:9781450302036
          DOI:10.1145/1869459

        Copyright © 2010 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 17 October 2010

        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!