research-article

Clowns to the left of me, jokers to the right (pearl): dissecting data structures

Published:07 January 2008Publication History

Abstract

This paper introduces a small but useful generalisation to the 'derivative' operation on datatypes underlying Huet's notion of 'zipper', giving a concrete representation to one-hole contexts in data which is undergoing transformation. This operator, 'dissection', turns a container-like functor into a bifunctor representing a one-hole context in which elements to the left of the hole are distinguished in type from elements to its right.

I present dissection here as a generic program, albeit for polynomial functors only. The notion is certainly applicable more widely, but here I prefer to concentrate on its diverse applications. For a start, map-like operations over the functor and fold-like operations over the recursive data structure it induces can be expressed by tail recursion alone. Further, the derivative is readily recovered from the dissection. Indeed, it is the dissection structure which delivers Huet's operations for navigating zippers.

The original motivation for dissection was to define 'division', capturing the notion of leftmost hole, canonically distinguishing values with no elements from those with at least one. Division gives rise to an isomorphism corresponding to the remainder theorem in algebra. By way of a larger example, division and dissection are exploited to give a relatively efficient generic algorithm for abstracting all occurrences of one term from another in a first-order syntax. The source code for the paper is available online and compiles with recent extensions to the Glasgow Haskell Compiler.

References

  1. Michael Abbott, Thorsten Altenkirch, and Neil Ghani. Containers -- constructing strictly positive types. Theoretical Computer Science, 342: 3--27, September 2005a. Applied Semantics: Selected Topics. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Michael Abbott, Thorsten Altenkirch, Neil Ghani, and Conor McBride. d for data: derivatives of data structures. Fundamenta Informaticae, 65 (1&2): 1--28, 2005b. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Mads Sig Ager, Dariusz Biernacki, Olivier Danvy, and Jan Midtgaard. A functional correspondence between evaluators and abstract machines. In PPDP, pages 8--19. ACM, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. William Aitken and John Reppy. Abstract value constructors. Technical Report TR 92-1290, Cornell University, 1992.Google ScholarGoogle Scholar
  5. Michael Barr and Charles Wells. Toposes, Triples and Theories, chapter 9. Number 278 in Grundlehren der Mathematischen Wissenschaften. Springer, New York, 1984.Google ScholarGoogle Scholar
  6. Richard Bird and Oege de Moor. Algebra of Programming. Prentice Hall, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Richard Bird and Ross Paterson. de Bruijn notation as a nested datatype. Journal of Functional Programming, 9 (1): 77--92, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Janusz Brzozowski. Derivatives of regular expressions. Journal of the ACM, 11 (4): 481--494, 1964. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Jean-Christophe Filliatre. Backtracking iterators. Technical Report 1428, CNRS-LRI, January 2006.Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Jeremy Gibbons. Datatype-generic programming. In Roland Backhouse, Jeremy Gibbons, Ralf Hinze, and Johan Jeuring, editors, Spring School on Datatype-Generic Programming, volume 4719 of Lecture Notes in Computer Science. Springer-Verlag, 2007. To appear. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Thomas Hallgren. Fun with functional dependencies. In Joint Winter Meeting of the Departments of Science and Computer Engineering, Chalmers University of Technology and Goteborg University, Varberg, Sweden., January 2001.Google ScholarGoogle Scholar
  12. Ralf Hinze, Johan Jeuring, and Andres Loeh. Type-indexed data types. Science of Computer Programmming, 51: 117--151, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Martin Hofmann and Steffen Jost. Static prediction of heap space usage for first-order functional programs. In Proceedings of the 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), pages 185--197. ACM, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Gerard Huet. The Zipper. Journal of Functional Programming, 7 (5): 549--554, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Patrik Jansson and Johan Jeuring. PolyP-a polytypic programming language extension. In Proceedings of POPL '97, pages 470--482. ACM, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Andre Joyal. Foncteurs analytiques et especes de structures. In Combinatoire enumerative, number 1234 in LNM, pages 126--159. 1986.Google ScholarGoogle Scholar
  17. Conor McBride. The Derivative of a Regular Type is its Type of One-Hole Contexts. Available at http://www.cs.nott.ac.uk/~ctm/diff.pdf, 2001.Google ScholarGoogle Scholar
  18. Conor McBride. Faking It (Simulating Dependent Types in Haskell). Journal of Functional Programming, 12 (4&5): 375--392, 2002. Special Issue on Haskell. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Matthias Neubauer, Peter Thiemann, Martin Gasbichler, and Michael Sperber. A Functional Notation for Functional Dependencies. In The 2001 ACM SIGPLAN Haskell Workshop, Firenze, Italy, September 2001.Google ScholarGoogle Scholar
  20. Simon Peyton Jones, Mark Jones, and Erik Meijer. Type classes: an exploration of the design space. In Proceedings of the Haskell Workshop, Amsterdam, The Netherlands, June 1997.Google ScholarGoogle Scholar
  21. Philip Wadler and Stephen Blott. How to make ad-hoc polymorphism less ad hoc. In 16th ACM Symposium on Principles of Programming Languages, pages 60--76. ACM, January 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Clowns to the left of me, jokers to the right (pearl): dissecting data structures

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!