skip to main content
10.1145/2503778.2503781acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Understanding idiomatic traversals backwards and forwards

Published:23 September 2013Publication History

ABSTRACT

We present new ways of reasoning about a particular class of effectful Haskell programs, namely those expressed as idiomatic traversals. Starting out with a specific problem about labelling and unlabelling binary trees, we extract a general inversion law, applicable to any monad, relating a traversal over the elements of an arbitrary traversable type to a traversal that goes in the opposite direction. This law can be invoked to show that, in a suitable sense, unlabelling is the inverse of labelling. The inversion law, as well as a number of other properties of idiomatic traversals, is a corollary of a more general theorem characterising traversable functors as finitary containers: an arbitrary traversable object can be decomposed uniquely into shape and contents, and traversal be understood in terms of those. Proof of the theorem involves the properties of traversal in a special idiom related to the free applicative functor.

References

  1. R. Bird and L. Meertens. Nested datatypes. In Mathematics of Program Construction, volume 1422 of Lecture Notes in Computer Science, pages 52--67. Springer, 1998. 10.1007/BFb0054285. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. P. Capriotti and A. Kaposi. Free applicative functors. University of Nottingham. http://paolocapriotti.com/blog/2013/04/03/free-applicative-functors/, Apr. 2013.Google ScholarGoogle Scholar
  3. N. Gambino and M. Hyland. Wellfounded trees and dependent polynomial functors. In Types for Proofs and Programs, volume 3085 of Lecture Notes in Computer Science, pages 210--225. Springer, 2004. 10.1007/978-3-540-24849-1_14.Google ScholarGoogle Scholar
  4. J. Gibbons and B. C. d. S. Oliveira. The essence of the Iterator pattern. Journal of Functional Programming, 19 (3,4): 377--402, 2009. 10.1017/S0956796809007291. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. J.-Y. Girard. Normal functors, power series and ł-calculus. Annals of Pure and Applied Logic, 37 (2): 129--177, 1988. 10.1016/0168-0072(88)90025--5.Google ScholarGoogle ScholarCross RefCross Ref
  6. G. Hutton and D. Fulger. Reasoning About Effects: Seeing the Wood Through the Trees. In Trends in Functional Programming, pre-proceedings, Nijmegen, The Netherlands, 2008.Google ScholarGoogle Scholar
  7. M. Jaskelioff and O. Rypácek. An investigation of the laws of traversals. In Mathematically Structured Functional Programming, volume 76 of Electronic Proceedings in Theoretical Computer Science, pages 40--49, 2012. 10.4204/EPTCS.76.5.Google ScholarGoogle Scholar
  8. C. McBride and R. Paterson. Applicative programming with effects. Journal of Functional Programming, 18 (1): 1--13, 2008. 10.1017/S0956796807006326. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. E. Moggi, G. Bellè, and B. Jay. Monads, shapely functors, and traversals. Electronic Notes in Theoretical Computer Science, 29: 187--208, 1999. 10.1016/S1571-0661(05)80316-0. Proceedings of Category Theory and Computer Science.Google ScholarGoogle ScholarCross RefCross Ref
  10. R. O'Connor and M. Jaskelioff. On the static nature of traversals. http://r6.ca/blog/20121209T182914Z.html, Dec. 2012.Google ScholarGoogle Scholar
  11. O. Rypácek. Labelling polynomial functors: A coherent approach. Manuscript, Mar. 2010.Google ScholarGoogle Scholar
  12. J. Voigtländer. Free theorems involving type constructor classes. In International Conference on Functional Programming, pages 173--184. ACM, 2009. 10.1145/1596550.1596577. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. P. Wadler. Theorems for free! In Functional Programming Languages and Computer Architecture, pages 347--359. ACM, 1989. 10.1145/99370.99404. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Understanding idiomatic traversals backwards and forwards

                  Recommendations

                  Comments

                  Login options

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

                  Sign in
                  • Published in

                    cover image ACM Conferences
                    Haskell '13: Proceedings of the 2013 ACM SIGPLAN symposium on Haskell
                    September 2013
                    158 pages
                    ISBN:9781450323833
                    DOI:10.1145/2503778

                    Copyright © 2013 ACM

                    Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

                    Publisher

                    Association for Computing Machinery

                    New York, NY, United States

                    Publication History

                    • Published: 23 September 2013

                    Permissions

                    Request permissions about this article.

                    Request Permissions

                    Check for updates

                    Qualifiers

                    • research-article

                    Acceptance Rates

                    Haskell '13 Paper Acceptance Rate13of33submissions,39%Overall Acceptance Rate57of143submissions,40%

                    Upcoming Conference

                    ICFP '24

                  PDF Format

                  View or Download as a PDF file.

                  PDF

                  eReader

                  View online with eReader.

                  eReader