A Notation for Comonads

  • Dominic OrchardEmail author
  • Alan Mycroft
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 8241)


The category-theoretic concept of a monad occurs widely as a design pattern for functional programming with effects. The utility and ubiquity of monads is such that some languages provide syntactic sugar for this pattern, further encouraging its use. We argue that comonads, the dual of monads, similarly provide a useful design pattern, capturing notions of context dependence. However, comonads remain relatively under-used compared to monads—due to a lack of knowledge of the design pattern along with the lack of accompanying simplifying syntax.

We propose a lightweight syntax for comonads in Haskell, analogous to the do-notation for monads, and provide examples of its use. Via our notation, we also provide a tutorial on programming with comonads.


Data Type Design Pattern Categorical Semantic Local Operation Suffix Tree 
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.



We thank Jeremy Gibbons, Ralf Hinze, Tomas Petricek, Tarmo Uustalu, and Varmo Vene for helpful discussions, and to the anonymous reviewers for their comments on this paper and an earlier draft. This research was supported by an EPSRC Doctoral Training Award.


  1. 1.
    Wadler, P.: The essence of functional programming. In: Proceedings of POPL ’92, pp. 1–14. ACM (1992)Google Scholar
  2. 2.
    Wadler, P.: Monads for functional programming. In: Jeuring, J., Meijer, E. (eds.) AFP 1995. LNCS, vol. 925, pp. 24–52. Springer, Heidelberg (1995)Google Scholar
  3. 3.
    Petricek, T., Syme, D.: Syntax Matters: writing abstract computations in F#. Pre-proceedings of TFP (Trends in Functional Programming), St. Andrews, Scotland (2012)Google Scholar
  4. 4.
    Uustalu, T., Vene, V.: The essence of dataflow programming. In: Horváth, Z. (ed.) CEFP 2005. LNCS, vol. 4164, pp. 135–167. Springer, Heidelberg (2006)Google Scholar
  5. 5.
    Uustalu, T., Vene, V.: Comonadic functional attribute evaluation. Trends Funct. Program. 6, 145–160 (2007)Google Scholar
  6. 6.
    Orchard, D., Bolingbroke, M., Mycroft, A.: Ypnos: declarative, parallel structured grid programming. In: DAMP ’10, pp. 15–24. ACM, NY (2010)Google Scholar
  7. 7.
    Kieburtz, R.B.: Codata and Comonads in Haskell (1999) (unpublished)Google Scholar
  8. 8.
    Uustalu, T., Vene, V.: Comonadic notions of computation. Electron. Notes Theor. Comput. Sci. 203, 263–284 (2008)MathSciNetCrossRefGoogle Scholar
  9. 9.
    Huet, G.: The zipper. J. Funct. Program. 7, 549–554 (1997)MathSciNetCrossRefzbMATHGoogle Scholar
  10. 10.
    McBride, C.: The derivative of a regular type is its type of one-hole contexts. Unpublished manuscript (2001)Google Scholar
  11. 11.
    Ahman, D., Chapman, J., Uustalu, T.: When is a container a comonad? In: Birkedal, L. (ed.) FOSSACS 2012. LNCS, vol. 7213, pp. 74–88. Springer, Heidelberg (2012)Google Scholar
  12. 12.
    Orchard, D.: Programming contextual computations (2013) Forthcoming PhD dissertation.
  13. 13.
    Lambek, J., Scott, P.: Introduction to higher-order categorical logic. Cambridge University Press, Cambridge (1988)zbMATHGoogle Scholar
  14. 14.
    Moggi, E.: Computational lambda-calculus and monads. In: Logic in Computer Science, LICS’89, pp. 14–23. IEEE (1989)Google Scholar
  15. 15.
    Moggi, E.: Notions of computation and monads. Inf. Comput. 93, 55–92 (1991)MathSciNetCrossRefzbMATHGoogle Scholar
  16. 16.
    Hughes, J.: Programming with arrows. In: Vene, V., Uustalu, T. (eds.) AFP 2004. LNCS, vol. 3622, pp. 73–129. Springer, Heidelberg (2005)Google Scholar
  17. 17.
    Paterson, R.: A new notation for arrows. In: ACM SIGPLAN Notices, vol. 36, pp. 229–240. ACM (2001)Google Scholar
  18. 18.
    Abbott, M., Altenkirch, T., Ghani, N.: Containers: constructing strictly positive types. Theor. Comput. Sci. 342, 3–27 (2005)MathSciNetCrossRefzbMATHGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2013

Authors and Affiliations

  1. 1.Computer LaboratoryUniversity of CambridgeCambridgeUK

Personalised recommendations