When Is a Container a Comonad?

  • Danel Ahman
  • James Chapman
  • Tarmo Uustalu
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7213)


Abbott, Altenkirch, Ghani and others have taught us that many parameterized datatypes (set functors) can be usefully analyzed via container representations in terms of a set of shapes and a set of positions in each shape. This paper builds on the observation that datatypes often carry additional structure that containers alone do not account for. We introduce directed containers to capture the common situation where every position in a datastructure determines another datastructure, informally, the sub-datastructure rooted by that position. Some natural examples are non-empty lists and node-labelled trees, and datastructures with a designated position (zippers). While containers denote set functors via a fully-faithful functor, directed containers interpret fully-faithfully into comonads. But more is true: every comonad whose underlying functor is a container is represented by a directed container. In fact, directed containers are the same as containers that are comonads. We also describe some constructions of directed containers. We have formalized our development in the dependently typed programming language Agda.


  1. 1.
    Abbott, M., Altenkirch, T., Ghani, N.: Containers: Constructing strictly positive types. Theor. Comput. Sci. 342(1), 3–27 (2005)MathSciNetzbMATHCrossRefGoogle Scholar
  2. 2.
    Abbott, M., Altenkirch, T., Ghani, N., McBride, C.: Constructing Polymorphic Programs with Quotient Types. In: Kozen, D. (ed.) MPC 2004. LNCS, vol. 3125, pp. 2–15. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  3. 3.
    Abbott, M., Altenkirch, T., Ghani, N., McBride, C.: δ for data: Differentiating data structures. Fund. Inform. 65(1-2), 1–28 (2005)MathSciNetzbMATHGoogle Scholar
  4. 4.
    Abbott, M.: Categories of Containers. Ph.D. thesis, University of Leicester (2003)Google Scholar
  5. 5.
    Altenkirch, T., Morris, P.: Indexed containers. In: Proc. of 24th Ann. IEEE Symp. on Logic in Computer Science, LICS 2009, pp. 277–285. IEEE CS Press (2009)Google Scholar
  6. 6.
    Brookes, S., Geva, S.: Computational comonads and intensional semantics. In: Fourman, M.P., Johnstone, P.T., Pitts, A.M. (eds.) Applications of Categories in Computer Science, London. Math. Society Lect. Note Series, vol. 77, pp. 1–44. Cambridge Univ. Press (1992)Google Scholar
  7. 7.
    Capobianco, S., Uustalu, T.: A categorical outlook on cellular automata. In: Kari, J. (ed.) Proc. of 2nd Symp. on Cellular Automata, JAC 2010. TUCS Lecture Note Series, vol. 13, pp. 88–89. Turku Centre for Comput. Sci. (2011)Google Scholar
  8. 8.
    Dybjer, P.: Representing inductively defined sets by wellorderings in Martin-Löf’s type theory. Theor. Comput. Sci. 176(1-2), 329–335 (1997)MathSciNetzbMATHCrossRefGoogle Scholar
  9. 9.
    Gambino, N., Hyland, M.: Wellfounded Trees and Dependent Polynomial Functors. In: Berardi, S., Coppo, M., Damiani, F. (eds.) TYPES 2003. LNCS, vol. 3085, pp. 210–225. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  10. 10.
    Gambino, N., Kock, J.: Polynomial functors and polynomial monads. Tech. Rep. 867, Centre de Recerca Matemàtica, Barcelona (2009)Google Scholar
  11. 11.
    Girard, J.Y.: Normal functors, power series and lambda-calculus. Ann. of Pure and Appl. Logic 37(2), 129–177 (1988)MathSciNetzbMATHCrossRefGoogle Scholar
  12. 12.
    Hasuo, I., Jacobs, B., Uustalu, T.: Categorical Views on Computations on Trees. In: Arge, L., Cachin, C., Jurdziński, T., Tarlecki, A. (eds.) ICALP 2007. LNCS, vol. 4596, pp. 619–630. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  13. 13.
    Huet, G.: The zipper. J. of Funct. Program. 7, 549–554 (1997)MathSciNetzbMATHCrossRefGoogle Scholar
  14. 14.
    Joyal, A.: Foncteurs analytiques et espèces de structures. In: Labelle, G., Leroux, P. (eds.) Combinatoire énumerative. Lect. Notes in Math., vol. 1234, pp. 126–159. Springer, Heidelberg (1987)CrossRefGoogle Scholar
  15. 15.
    Kock, J.: Polynomial functors and trees. Int. Math. Research Notices 2011(3), 609–673 (2011)MathSciNetzbMATHGoogle Scholar
  16. 16.
    Moerdijk, I., Palmgren, E.: Wellfounded trees in categories. Ann. of Pure and Appl. Logic 104(1-3), 189–218 (2000)MathSciNetzbMATHCrossRefGoogle Scholar
  17. 17.
    Morris, P.: Constructing Universes for Generic Programming. Ph.D. thesis, University of Nottingham (2007)Google Scholar
  18. 18.
    Norell, U.: Towards a Practical Programming Language Based on Dependent type Theory. Ph.D. thesis, Chalmers University of Technology (2007)Google Scholar
  19. 19.
    Prince, R., Ghani, N., McBride, C.: Proving Properties about Lists using Containers. In: Garrigue, J., Hermenegildo, M. (eds.) FLOPS 2008. LNCS, vol. 4989, pp. 97–112. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  20. 20.
    Uustalu, T., Vene, V.: The Essence of Dataflow Programming. In: Yi, K. (ed.) APLAS 2005. LNCS, vol. 3780, pp. 2–18. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  21. 21.
    Uustalu, T., Vene, V.: Attribute evaluation is comonadic. In: van Eekelen, M. (ed.) Trends in Functional Programming, vol. 6, pp. 145–162. Intellect (2007)Google Scholar
  22. 22.
    Uustalu, T., Vene, V.: Comonadic notions of computation. In: Adámek, J., Kupke, C. (eds.) Proc. of 9th Int. Wksh. on Coalgebraic Methods in Computer Science, CMCS 2008. Electron. Notes in Theor. Comput. Sci., vol. 203(5), pp. 263–284. Elsevier (2008)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Danel Ahman
    • 1
  • James Chapman
    • 2
  • Tarmo Uustalu
    • 2
  1. 1.Computer LaboratoryUniversity of CambridgeCambridgeUnited Kingdom
  2. 2.Institute of CyberneticsTallinn University of TechnologyTallinnEstonia

Personalised recommendations