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.
- }}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 Scholar
Digital Library
- }}Boost. The Boost C++ libraries. http://www.boost.org/, 2010.Google Scholar
- }}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 Scholar
Digital Library
- }}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 Scholar
Digital Library
- }}M. Chakravarty, G. Keller, S. Peyton Jones, and S. Marlow. Associated types with class. pages 1--13, 2005a.Google Scholar
- }}M. Chakravarty, G. Keller, and Simon Peyton Jones. Associated type synonyms. In ICFP '05, pages 241--253, 2005b. Google Scholar
Digital Library
- }}C. Chambers and G. T. Leavens. Typechecking and modules for multimethods. ACM Transactions on Programming Languages and Systems, 17(6):805--843, 1995. Google Scholar
Digital Library
- }}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 Scholar
Digital Library
- }}W. R. Cook. On understanding data abstraction, revisited. SIGPLAN Not., 44(10):557--572, 2009. Google Scholar
Digital Library
- }}W. R. Cook and J. Palsberg. A denotational semantics of inheritance and its correctness. Inf. Comput., 114(2):329--350, 1994. Google Scholar
Digital Library
- }}O. Danvy. Functional unparsing. J. Funct. Program., 8(6):621-- 625, 1998. Google Scholar
Digital Library
- }}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 Scholar
- }}G. Dos Reis and B. Stroustrup. Specifying C++ concepts. In POPL '06, pages 295--308, 2006. Google Scholar
Digital Library
- }}I. Dragos and M. Odersky. Compiling generics through userdirected type specialization. In ICOOOLPS '09, pages 42--47, 2009. Google Scholar
Digital Library
- }}D. Dreyer, R. Harper, M. M. T. Chakravarty, and G. Keller. Modular type classes. In POPL '07, pages 63--70, 2007. Google Scholar
Digital Library
- }}B. Emir, A. Kennedy, C. V. Russo, and D. Yu. Variance and generalized constraints for C# generics. In ECOOP, pages 279--303, 2006. Google Scholar
Digital Library
- }}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 Scholar
Digital Library
- }}J. Gibbons. Patterns in datatype-generic programming. In The Fun of Programming, Cornerstones in Computing, pages 41--60. Palgrave, 2003.Google Scholar
- }}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 Scholar
Digital Library
- }}F. Haftmann and M. Wenzel. Constructive type classes in Isabelle. In TYPES, pages 160--174, 2006. Google Scholar
Digital Library
- }}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 Scholar
Digital Library
- }}K. Honda. Types for dynamic interaction. In CONCUR '93, pages 509--523, 1993. Google Scholar
Digital Library
- }}J. Hughes. Restricted data types in Haskell. In Haskell Workshop, 1999.Google Scholar
- }}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 Scholar
- }}M. P. Jones. Type classes with functional dependencies. In ESOP '00, pages 230--244, 2000. Google Scholar
Digital Library
- }}W. Kahl and J. Scheffczyk. Named instances for Haskell type classes. In Haskell Workshop, 2001.Google Scholar
- }}A. Kennedy and C. V. Russo. Generalized algebraic data types and object-oriented programming. OOPSLA '05, pages 21--40, 2005. Google Scholar
Digital Library
- }}O. Kiselyov, R. Lammel, and K. Schupke. Strongly typed heterogeneous collections. In Haskell '04, pages 96--107, 2004. Google Scholar
Digital Library
- }}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 Scholar
- }}R. Lammel and S. P. Jones. Scrap your boilerplate with class: a extensible generic functions. In ICFP '05, pages 204--215, 2005. Google Scholar
Digital Library
- }}R. Lammel and K. Ostermann. Software extension and integration a with type classes. In GPCE '06, pages 161--170, 2006. Google Scholar
Digital Library
- }}D. B. MacQueen. Modules for Standard ML. In LISP and Functional Programming, pages 198--207, 1984. Google Scholar
Digital Library
- }}C. McBride. Faking it: Simulating dependent types in Haskell. J. Funct. Program., 12(5):375--392, 2002. Google Scholar
Digital Library
- }}J. C. Mitchell and G. D. Plotkin. Abstract types have existential type. ACM Trans. Program. Lang. Syst., 10(3):470--502, 1988. Google Scholar
Digital Library
- }}A. Moors, F. Piessens, and M. Odersky. Generics of a higher kind. In OOPSLA '08, pages 423--438, 2008. Google Scholar
Digital Library
- }}D. Musser and A. A. Stepanov. Generic programming. In Symbolic and algebraic computation: ISSAC 88, pages 13--25. Springer, 1988. Google Scholar
Digital Library
- }}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 Scholar
Digital Library
- }}M. Odersky, 2006. URL http://www.artima.com/weblogs/ viewpost.jsp?thread=179766.Google Scholar
- }}M. Odersky. The Scala Language Specification, Version 2.8. EPFL, 2010. URL http://www.scala-lang.org/docu/files/ ScalaReference.pdf.Google Scholar
- }}M. Odersky and A. Moors. Fighting bit rot with types (experience report: Scala collections). In FSTTCS, pages 427--451, 2009.Google Scholar
- }}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 Scholar
Cross Ref
- }}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 Scholar
- }}B. C. d. S. Oliveira and J. Gibbons. Scala for generic programmers. In WGP '08, pages 25--36, 2008. Google Scholar
Digital Library
- }}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 Scholar
- }}D. Orchard and T. Schrijvers. Haskell type constraints unleashed. In FLOPS '10. Springer-Verlag, 2010. Google Scholar
Digital Library
- }}S. Peyton Jones, editor. Haskell 98 Language and Libraries - The Revised Report. Cambridge University Press, Cambridge, England, 2003.Google Scholar
- }}S. Peyton Jones, M. Jones, and E. Meijer. Type classes: exploring the design space. In Haskell Workshop, 1997.Google Scholar
- }}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 Scholar
Digital Library
- }}S. Peyton Jones, S. Marlow, et al. The Glasgow Haskell Compiler, 2009. URL http://www.haskell.org/ghc/.Google Scholar
- }}T. Schrijvers, S. Peyton Jones, M. Chakravarty, and M. Sulzmann. Type checking with open type functions. In ICFP '08, pages 51--62, 2008. Google Scholar
Digital Library
- }}J. S. Shapiro, S. Sridhar, and M. S. Doerrie. BitC language specification, 2008. URL http://www.coyotos.org/docs/bitc/ spec.html.Google Scholar
- }}J. G. Siek and A. Lumsdaine. Essential language support for generic programming. In PLDI '05, pages 73--84, 2005. Google Scholar
Digital Library
- }}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 Scholar
Digital Library
- }}M. Sozeau and N. Oury. First-class type classes. In TPHOLs '08, pages 278--293, 2008. Google Scholar
Digital Library
- }}P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad hoc. In POPL '89, pages 60--76, 1989. Google Scholar
Digital Library
- }}S. Wehr. JavaGI: A Language with Generalized Interfaces. PhD thesis, University of Freiburg, Department of Computer Science, December 2009.Google Scholar
Index Terms
Type classes as objects and implicits
Recommendations
Type classes in Haskell
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 ...
Type classes as objects and implicits
OOPSLA '10: Proceedings of the ACM international conference on Object oriented programming systems languages and applicationsType 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 ...
Type families with class, type classes with family
Haskell '15: Proceedings of the 2015 ACM SIGPLAN Symposium on HaskellType classes and type families are key ingredients in Haskell programming. Type classes were introduced to deal with ad-hoc polymorphism, although with the introduction of functional dependencies, their use expanded to type-level programming. Type ...







Comments