Generic Programming with Adjunctions

  • Ralf Hinze
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7470)


Adjunctions are among the most important constructions in mathematics. These lecture notes show they are also highly relevant to datatype-generic programming. First, every fundamental datatype—sums, products, function types, recursive types—arises out of an adjunction. The defining properties of an adjunction give rise to well-known laws of the algebra of programming. Second, adjunctions are instrumental in unifying and generalising recursion schemes. We discuss a multitude of basic adjunctions and show that they are directly relevant to programming and to reasoning about programs.


Natural Transformation Category Theory Universal Property Recursive Call Left Adjoint 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Jones, M.P.: A system of constructor classes: overloading and implicit higher-order polymorphism. Journal of Functional Programming 5(1), 1–35 (1995)zbMATHCrossRefGoogle Scholar
  2. 2.
    Wadler, P.: Theorems for free! In: The Fourth International Conference on Functional Programming Languages and Computer Architecture (FPCA 1989), pp. 347–359. Addison-Wesley Publishing Company, London (1989)CrossRefGoogle Scholar
  3. 3.
    Wadler, P.: Comprehending monads. In: Proceedings of the 1990 ACM Conference on LISP and Functional Programming, pp. 61–78. ACM Press, Nice (1990)CrossRefGoogle Scholar
  4. 4.
    McBride, C., Paterson, R.: Functional Pearl: Applicative programming with effects. Journal of Functional Programming 18(1), 1–13 (2008)zbMATHCrossRefGoogle Scholar
  5. 5.
    Meijer, E., Fokkinga, M., Paterson, R.: Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 124–144. Springer, Heidelberg (1991)CrossRefGoogle Scholar
  6. 6.
    Gibbons, J., Jones, G.: The under-appreciated unfold. In: Felleisen, M., Hudak, P., Queinnec, C. (eds.) Proceedings of the Third ACM SIGPLAN International Conference on Functional Programming, pp. 273–279. ACM Press (1998)Google Scholar
  7. 7.
    Kan, D.M.: Adjoint functors. Transactions of the American Mathematical Society 87(2), 294–329 (1958)MathSciNetzbMATHCrossRefGoogle Scholar
  8. 8.
    Mac Lane, S.: Categories for the Working Mathematician, 2nd edn. Graduate Texts in Mathematics. Springer, Berlin (1998)zbMATHGoogle Scholar
  9. 9.
    Bird, R., De Moor, O.: Algebra of Programming. Prentice Hall Europe, London (1997)zbMATHGoogle Scholar
  10. 10.
    Hinze, R.: A category theory primer (2010),
  11. 11.
    Hinze, R.: Adjoint folds and unfolds—an extended study. Science of Computer Programming (2011) (to appear)Google Scholar
  12. 12.
    Mulry, P.: Strong monads, algebras and fixed points. In: Fourman, M., Johnstone, P., Pitts, A. (eds.) Applications of Categories in Computer Science. Cambridge University Press (1992)Google Scholar
  13. 13.
    Lambek, J.: A fixpoint theorem for complete categories. Math. Zeitschr. 103, 151–161 (1968)MathSciNetzbMATHCrossRefGoogle Scholar
  14. 14.
    Hinze, R., James, D.W.H.: Reason isomorphically? In: Oliveira, B.C., Zalewski, M. (eds.) Proceedings of the 6th ACM SIGPLAN Workshop on Generic Programming (WGP 2010), pp. 85–96. ACM, New York (2010)CrossRefGoogle Scholar
  15. 15.
    Peyton Jones, S.: Haskell 98 Language and Libraries. Cambridge University Press (2003)Google Scholar
  16. 16.
    Cockett, R., Fukushima, T.: About Charity. Yellow Series Report 92/480/18, Dept. of Computer Science, Univ. of Calgary (June 1992)Google Scholar
  17. 17.
    The Coq Development Team: The Coq proof assistant reference manual (2010),
  18. 18.
    Goguen, J.A., Thatcher, J.W., Wagner, E.G., Wright, J.B.: Initial algebra semantics and continuous algebras. Journal of the ACM 24(1), 68–95 (1977)MathSciNetzbMATHCrossRefGoogle Scholar
  19. 19.
    Smyth, M.B., Plotkin, G.D.: The category-theoretic solution of recursive domain equations. SIAM Journal on Computing 11(4), 761–783 (1982)MathSciNetzbMATHCrossRefGoogle Scholar
  20. 20.
    Sheard, T., Pasalic, T.: Two-level types and parameterized modules. Journal of Functional Programming 14(5), 547–587 (2004)zbMATHCrossRefGoogle Scholar
  21. 21.
    Mendler, N.P.: Inductive types and type constraints in the second-order lambda calculus. Annals of Pure and Applied Logic 51(1-2), 159–172 (1991)MathSciNetzbMATHCrossRefGoogle Scholar
  22. 22.
    Giménez, E.: Codifying Guarded Definitions with Recursive Schemes. In: Smith, J., Dybjer, P., Nordström, B. (eds.) TYPES 1994. LNCS, vol. 996, pp. 39–59. Springer, Heidelberg (1995)CrossRefGoogle Scholar
  23. 23.
    Okasaki, C.: Purely Functional Data Structures. Cambridge University Press (1998)Google Scholar
  24. 24.
    Bird, R.S., Meertens, L.: Nested Datatypes. In: Jeuring, J. (ed.) MPC 1998. LNCS, vol. 1422, pp. 52–67. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  25. 25.
    Mycroft, A.: Polymorphic Type Schemes and Recursive Definitions. In: Paul, M., Robinet, B. (eds.) Programming 1984. LNCS, vol. 167, pp. 217–228. Springer, Heidelberg (1984)CrossRefGoogle Scholar
  26. 26.
    Hinze, R., Peyton Jones, S.: Derivable type classes. In: Hutton, G. (ed.) Proceedings of the 2000 ACM SIGPLAN Haskell Workshop. Electronic Notes in Theoretical Computer Science, vol. 41(1), pp. 5–35. Elsevier Science (2001); The preliminary proceedings appeared as a University of Nottingham technical reportGoogle Scholar
  27. 27.
    Trifonov, V.: Simulating quantified class constraints. In: Haskell 2003: Proceedings of the 2003 ACM SIGPLAN Workshop on Haskell, pp. 98–102. ACM, New York (2003)CrossRefGoogle Scholar
  28. 28.
    Lämmel, R., Peyton Jones, S.: Scrap your boilerplate with class: extensible generic functions. In: Pierce, B. (ed.) Proceedings of the 2005 International Conference on Functional Programming, Tallinn, Estonia, September 26–28 (2005)Google Scholar
  29. 29.
    Meertens, L.: Paramorphisms. Formal Aspects of Computing 4, 413–424 (1992)zbMATHCrossRefGoogle Scholar
  30. 30.
    Backhouse, R., Bijsterveld, M., Van Geldrop, R., Van der Woude, J.: Category theory as coherently constructive lattice theory (2003), Working Document, available from,
  31. 31.
    Bird, R., Paterson, R.: Generalised folds for nested datatypes. Formal Aspects of Computing 11(2), 200–222 (1999)Google Scholar
  32. 32.
    Hinze, R.: Efficient generalized folds. In: Jeuring, J. (ed.) Proceedings of the Second Workshop on Generic Programming, pp. 1–16 (2000); The Proceedings appeared as a technical report of Universiteit Utrecht, UU-CS-2000-19Google Scholar
  33. 33.
    Hinze, R.: Kan Extensions for Program Optimisation Or: Art and Dan Explain an Old Trick. In: Gibbons, J., Nogueira, P. (eds.) MPC 2012. LNCS, vol. 7342, pp. 324–362. Springer, Heidelberg (2012)Google Scholar
  34. 34.
    Eilenberg, S., MacLane, S.: General theory of natural equivalences. Transactions of the American Mathematical Society 58(2), 231–294 (1945)MathSciNetzbMATHCrossRefGoogle Scholar
  35. 35.
    Awodey, S.: Category Theory, 2nd edn. Oxford University Press (2010)Google Scholar
  36. 36.
    Barr, M., Wells, C.: Category Theory for Computing Science, 3rd edn. Les Publications CRM, Montréal (1999), The book is available from Centre de recherches mathématiques,
  37. 37.
    Pierce, B.C.: Basic Category Theory for Computer Scientists. The MIT Press (1991)Google Scholar
  38. 38.
    Rydeheard, D.: Adjunctions. In: Poigné, A., Pitt, D.H., Rydeheard, D.E., Abramsky, S. (eds.) Category Theory and Computer Programming. LNCS, vol. 240, pp. 51–57. Springer, Heidelberg (1986)CrossRefGoogle Scholar
  39. 39.
    Spivey, M.: A Categorical Approach to the Theory of Lists. In: van de Snepscheut, J.L.A. (ed.) MPC 1989. LNCS, vol. 375, pp. 399–408. Springer, Heidelberg (1989)CrossRefGoogle Scholar
  40. 40.
    Bird, R.: An introduction to the theory of lists. In: Broy, M. (ed.) Proceedings of the NATO Advanced Study Institute on Logic of Programming and Calculi of Discrete Design, Marktoberdorf, Germany, pp. 5–42. Springer, Heidelberg (1987)CrossRefGoogle Scholar
  41. 41.
    Bird, R.: A calculus of functions for program derivation. Technical Report PRG-64, Programming Research Group, Oxford University Computing Laboratory (1987)Google Scholar
  42. 42.
    Fokkinga, M.M., Meertens, L.: Adjunctions. Technical Report Memoranda Inf. 94-31, University of Twente, Enschede, Netherlands (June 1994)Google Scholar
  43. 43.
    Malcolm, G.: Data structures and program transformation. Science of Computer Programming 14(2-3), 255–280 (1990)MathSciNetzbMATHCrossRefGoogle Scholar
  44. 44.
    Fokkinga, M.M.: Law and Order in Algorithmics. PhD thesis, University of Twente (February 1992)Google Scholar
  45. 45.
    Pardo, A.: Generic accumulations. In: Gibbons, J., Jeuring, J. (eds.) Proceedings of the IFIP TC2 Working Conference on Generic Programming, Schloss Dagstuhl, pp. 49–78. Kluwer Academic Publishers (July 2002)Google Scholar
  46. 46.
    Hagino, T.: A Typed Lambda Calculus with Categorical Type Constructors. In: Pitt, D.H., Rydeheard, D.E., Poigné, A. (eds.) Category Theory and Computer Science. LNCS, vol. 283, pp. 140–157. Springer, Heidelberg (1987)CrossRefGoogle Scholar
  47. 47.
    Connelly, R.H., Morris, F.L.: A generalization of the trie data structure. Mathematical Structures in Computer Science 5(3), 381–418 (1995)MathSciNetzbMATHCrossRefGoogle Scholar
  48. 48.
    Okasaki, C.: Catenable double-ended queues. In: Proceedings of the 1997 ACM SIGPLAN International Conference on Functional Programming, Amsterdam, The Netherlands, pp. 66–74 (June 1997); ACM SIGPLAN Notices 32(8) (August 1997)Google Scholar
  49. 49.
    De Bruin, P.J.: Inductive types in constructive languages. PhD thesis, University of Groningen (1995)Google Scholar
  50. 50.
    Uustalu, T., Vene, V., Pardo, A.: Recursion schemes from comonads. Nordic J. of Computing 8, 366–390 (2001)MathSciNetzbMATHGoogle Scholar
  51. 51.
    Bartels, F.: Generalised coinduction. Math. Struct. Comp. Science 13, 321–348 (2003)MathSciNetzbMATHGoogle Scholar
  52. 52.
    Capretta, V., Uustalu, T., Vene, V.: Recursive coalgebras from comonads. Information and Computation 204(4), 437–468 (2006)MathSciNetzbMATHCrossRefGoogle Scholar
  53. 53.
    Backhouse, R., Bijsterveld, M., Van Geldrop, R., Van der Woude, J.: Categorical Fixed Point Calculus. In: Johnstone, P.T., Rydeheard, D.E., Pitt, D.H. (eds.) CTCS 1995. LNCS, vol. 953, pp. 159–179. Springer, Heidelberg (1995)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Ralf Hinze
    • 1
  1. 1.Department of Computer ScienceUniversity of OxfordOxfordEngland

Personalised recommendations