Classes of Arbitrary Kind

Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 11372)


The type class system in the Haskell Programming language provides a useful abstraction for a wide range of types, such as those that support comparison, serialization, ordering, between others. This system can be extended by the programmer by providing custom instances to one’s custom types. Yet, this is often a monotonous task. Some notions, such as equality, are very regular regardless if it is being encoded for a ground type or a type constructor. In this paper we present a technique that unifies the treatment of ground types and type constructors whenever possible. This reduces code duplication and improves consistency. We discuss the encoding of several classes in this form, including the generic programming facility in GHC.


Haskell Type classes Generic programming 


  1. 1.
    Bolingbroke, M.: Constraint Kinds (2011).
  2. 2.
    Bottu, G.J., Karachalias, G., Schrijvers, T., Oliveira, B.C.d.S., Wadler, P.: Quantified class constraints. In: Proceedings of the 10th International Symposium on Haskell, Haskell 2017. ACM (2017)Google Scholar
  3. 3.
    Cervesato, I., Pfenning, F.: A linear spine calculus. J. Log. Comput. 13(5), 639–688 (2003)MathSciNetCrossRefGoogle Scholar
  4. 4.
    Chakravarty, M.M.T., Keller, G., Peyton Jones, S., Marlow, S.: Associated types with class. In: Proceedings of the 32nd Symposium on Principles of Programming Languages, POPL 2005. ACM (2005)Google Scholar
  5. 5.
    Eisenberg, R.A., Weirich, S.: Dependently typed programming with singletons. In: Proceedings of the 2012 Haskell Symposium, Haskell 2012. ACM (2012)Google Scholar
  6. 6.
    Hinze, R.: Polytypic values possess polykinded types. In: Backhouse, R., Oliveira, J.N. (eds.) MPC 2000. LNCS, vol. 1837, pp. 2–27. Springer, Heidelberg (2000). Scholar
  7. 7.
    Jones, M.P.: Type classes with functional dependencies. In: Smolka, G. (ed.) ESOP 2000. LNCS, vol. 1782, pp. 230–244. Springer, Heidelberg (2000). Scholar
  8. 8.
    Magalhães, J.P., Dijkstra, A., Jeuring, J., Löh, A.: Ageneric deriving mechanism for haskell. In: Proceedings of the 3rd Symposium on Haskell, Haskell 2010. ACM (2010)Google Scholar
  9. 9.
    Miraldo, V.C., Serrano, A.: Sums of products for mutually recursive datatypes: the appropriationist’s view on generic programming. In: Proceedings of the 3rd International Workshop on Type-Driven Development, TyDe 2018. ACM (2018)Google Scholar
  10. 10.
    Noort, T.v., Rodriguez, A., Holdermans, S., Jeuring, J., Heeren, B.: A lightweight approach to datatype-generic rewriting. In: Proceedings of the Workshop on Generic Programming, WGP 2008. ACM (2008)Google Scholar
  11. 11.
    Peyton Jones, S., Jones, M., Meijer, E.: Type classes: an exploration of the design space. In: Haskell Workshop, Amsterdam (1997)Google Scholar
  12. 12.
    Pickering, M., Érdi, G., Peyton Jones, S., Eisenberg, R.A.: Pattern synonyms. In: Proceedings of the 9th International Symposium on Haskell, Haskell 2016. ACM (2016)Google Scholar
  13. 13.
    Schrijvers, T., Peyton Jones, S., Chakravarty, M., Sulzmann, M.: Type checking with open type functions. In: Proceedings of the 13th International Conference on Functional Programming, ICFP 2008. ACM (2008)Google Scholar
  14. 14.
    Serrano, A., Miraldo, V.C.: Generic programming of all kinds. In: Proceedings of the 11th Symposium on Haskell, Haskell 2018. ACM (2018)Google Scholar
  15. 15.
    de Vries, E., Löh, A.: True sums of products. In: Proceedings of the 10th Workshop on Generic Programming, WGP 2014. ACM (2014)Google Scholar
  16. 16.
    Wadler, P., Blott, S.: How to make ad-hoc polymorphism less ad hoc. In: Proceedings of the 16th Symposium on Principles of Programming Languages, POPL 1989. ACM (1989)Google Scholar
  17. 17.
    Weirich, S., Casinghino, C.: Arity-generic datatype-generic programming. In: Proceedings of the 4th Workshop on Programming Languages Meets Program Verification, PLPV 2010. ACM (2010)Google Scholar
  18. 18.
    Weirich, S., Voizard, A., de Amorim, P.H.A., Eisenberg, R.A.: A specification for dependent types in haskell. In: Proceedings ACM Programming Languages 1(ICFP) (2017)CrossRefGoogle Scholar
  19. 19.
    Xi, H., Chen, C., Chen, G.: Guarded recursive datatype constructors. In: Proceedings of the 30th Symposium on Principles of Programming Languages, POPL 2003. ACM (2003)Google Scholar
  20. 20.
    Yakushev, A.R., Holdermans, S., Löh, A., Jeuring, J.: Generic programming with fixed points for mutually recursive datatypes. In: Proceedings of the 14th International Conference on Functional Programming, ICFP 2009. ACM (2009)Google Scholar
  21. 21.
    Yorgey, B.A., Weirich, S., Cretin, J., Peyton Jones, S., Vytiniotis, D., Magalhães, J.P.: Giving haskell a promotion. In: Proceedings of the 8th Workshop on Types in Language Design and Implementation, TLDI 2012. ACM (2012)Google Scholar

Copyright information

© Springer Nature Switzerland AG 2019

Authors and Affiliations

  1. 1.Department of Information and Computing SciencesUtrecht UniversityUtrechtNetherlands

Personalised recommendations