skip to main content
research-article
Open Access
Artifacts Available
Artifacts Evaluated & Functional

Generic deriving of generic traversals

Published:30 July 2018Publication History
Skip Abstract Section

Abstract

Functional programmers have an established tradition of using traversals as a design pattern to work with recursive data structures. The technique is so prolific that a whole host of libraries have been designed to help in the task of automatically providing traversals by analysing the generic structure of data types. More recently, lenses have entered the functional scene and have proved themselves to be a simple and versatile mechanism for working with product types. They make it easy to focus on the salient parts of a data structure in a composable and reusable manner.

This paper uses the combination of lenses and traversals to give rise to a library with unprecedented expressivity and flexibility for querying and modifying complex data structures. Furthermore, since lenses and traversals are based on the generic shape of data, this information is used to generate code that is as efficient as hand-optimised versions. The technique leverages the structure of data to produce generic abstractions that are then eliminated by the standard workhorses of modern functional compilers: inlining and specialisation.

Skip Supplemental Material Section

Supplemental Material

a85-kiss.webm

References

  1. Michael D Adams and Thomas M DuBuisson. 2012. Template your boilerplate: Using Template Haskell for efficient generic programming. In ACM SIGPLAN Notices, Vol. 47. ACM, 13–24. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Michael D. Adams, Andrew Farmer, and José Pedro Magalhães. 2014. Optimizing SYB is Easy!. In Proceedings of the ACM SIGPLAN 2014 Workshop on Partial Evaluation and Program Manipulation (PEPM ’14). ACM, New York, NY, USA, 71–82. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Michael D. Adams, Andrew Farmer, and José Pedro Magalhães. 2015. Optimizing SYB Traversals is Easy! Sci. Comput. Program. 112, P2 (Nov. 2015), 170–193. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Lennart Augustsson. 2018. geniplate-mirror-0.7.6 library. http://hackage.haskell.org/package/geniplate-mirror-0.7.6Google ScholarGoogle Scholar
  5. Richard Bird, Jeremy Gibbons, Stefan Mehner, Janis Voigtlaender, and Tom Schrijvers. 2013. Understanding Idiomatic Traversals Backwards and Forwards. In Haskell Symposium. http://www.comlab.ox.ac.uk/jeremy.gibbons/publications/ uitbaf.pdf Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Maximilian C. Bolingbroke. 2011. Constraint Kinds for GHC. http://blog.omega-prime.co.uk/2011/09/10/ constraint-kinds-for-ghc/Google ScholarGoogle Scholar
  7. Joachim Breitner. 2018. Beyond correct and fast: Inspection Testing. CoRR abs/1803.07130 (2018). arXiv: 1803.07130 http://arxiv.org/abs/1803.07130Google ScholarGoogle Scholar
  8. Joachim Breitner, Richard A. Eisenberg, Simon Peyton Jones, and Stephanie Weirich. 2014. Safe Zero-cost Coercions for Haskell. SIGPLAN Not. 49, 9 (Aug. 2014), 189–202. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Manuel M. T. Chakravarty, Gabriele Keller, Simon Peyton Jones, and Simon Marlow. 2005. Associated types with class. In POPL ’05: Proceedings of the 32nd ACM SIGPLAN-SIGACT sysposium on Principles of programming languages. ACM Press, 1–13. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Edsko de Vries and Andres Löh. 2014. True sums of products. In Proceedings of the 10th ACM SIGPLAN workshop on Generic programming. ACM, 83–94. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Richard A. Eisenberg, Dimitrios Vytiniotis, Simon Peyton Jones, and Stephanie Weirich. 2014. Closed Type Families with Overlapping Equations. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’14). ACM, New York, NY, USA, 671–683. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Richard A. Eisenberg, Stephanie Weirich, and Hamidhasan G. Ahmed. 2016. Visible Type Application. In Proceedings of the 25th European Symposium on Programming Languages and Systems - Volume 9632. Springer-Verlag New York, Inc., New York, NY, USA, 229–254.Google ScholarGoogle Scholar
  13. Andrew Farmer. 2015. HERMIT: Mechanized Reasoning during Compilation in the Glasgow Haskell Compiler. Ph.D. Dissertation. University of Kansas, USA. http://hdl.handle.net/1808/19416Google ScholarGoogle Scholar
  14. Ralf Hinze. 2000. A New Approach to Generic Functional Programming. In Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’00). ACM, New York, NY, USA, 119–132. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Mauro Jaskelioff and Russell O’Connor. 2015. A Representation Theorem for Second-Order Functionals. Journal of Functional Programming 25, e13 (2015).Google ScholarGoogle ScholarCross RefCross Ref
  16. Edward Kmett. 2018. lens-4.16 library. https://hackage.haskell.org/package/lens-4.16Google ScholarGoogle Scholar
  17. Ralf Lämmel and Simon Peyton Jones. 2003. Scrap Your Boilerplate: A Practical Design Pattern for Generic Programming. In Types in Languages Design and Implementation. ACM Press, New York, NY, USA, 26–37. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Ralf Lämmel and Simon Peyton Jones. 2004. Scrap More Boilerplate: Reflection, Zips, and Generalised Casts. In Proceedings of the Ninth ACM SIGPLAN International Conference on Functional Programming (ICFP ’04). ACM, New York, NY, USA, 244–255. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. José Pedro Magalhães, Atze Dijkstra, Johan Jeuring, and Andres Löh. 2010. A Generic Deriving Mechanism for Haskell. In Proceedings of the Third ACM Haskell Symposium on Haskell (Haskell ’10). ACM, New York, NY, USA, 37–48. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. José Pedro Magalhães. 2012. Optimisation of generic programs through inlining. In Symposium on Implementation and Application of Functional Languages. Springer, 104–121.Google ScholarGoogle Scholar
  21. José Pedro Magalhães. 2014. Generic Programming with Multiple Parameters. In Functional and Logic Programming, Michael Codish and Eijiro Sumii (Eds.). Springer International Publishing, Cham, 136–151.Google ScholarGoogle Scholar
  22. Conor McBride and Ross Paterson. 2008. Applicative programming with effects. Journal of functional programming 18, 1 (2008), 1–13. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Neil Mitchell and Colin Runciman. 2007. Uniform boilerplate and list processing. In Proceedings of the ACM SIGPLAN workshop on Haskell workshop. ACM, 49–60. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Russell O’Connor. 2011. Functor is to Lens as Applicative is to Biplate: Introducing Multiplate. CoRR abs/1103.2841 (2011).Google ScholarGoogle Scholar
  25. Simon Peyton Jones and Simon Marlow. 2002. Secrets of the glasgow haskell compiler inliner. Journal of Functional Programming 12, 4-5 (2002), 393–434. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Mark Shields. 2007. Practical Type Inference for Arbitraryrank Types. J. Funct. Program. 17, 1 (Jan. 2007), 1–82. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Simon Peyton Jones, Stephanie Weirich, Richard A Eisenberg, and Dimitrios Vytiniotis. 2016. A reflection on types. In A List of Successes That Can Change the World. Springer, 292–317.Google ScholarGoogle Scholar
  28. Simon L Peyton Jones and AndréL M Santos. 1998. A transformation-based optimiser for Haskell. Science of computer programming 32, 1-3 (1998), 3–47. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Matthew Pickering, Jeremy Gibbons, and Nicolas Wu. 2017. Profunctor Optics: Modular Data Accessors. Programming Journal 1, 2 (2017), 7.Google ScholarGoogle ScholarCross RefCross Ref
  30. Martin Sulzmann, Gregory J. Duck, Simon Peyton Jones, and Peter J. Stuckey. 2007. Understanding Functional Dependencies via Constraint Handling Rules. J. Funct. Program. 17, 1 (Jan. 2007), 83–129. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Twan van Laarhoven. 2009. CPS-Based Functional References. (July 2009). http://www.twanvl.nl/blog/haskell/ cps-functional-referencesGoogle ScholarGoogle Scholar
  32. Sjoerd Visscher and Li-yao Xia. 2018. one-liner-1.0 library. http://hackage.haskell.org/package/one-liner-1.0Google ScholarGoogle Scholar
  33. Dimitrios Vytiniotis, Simon Peyton Jones, Tom Schrijvers, and Martin Sulzmann. 2011. Outsidein(x) Modular Type Inference with Local Assumptions. J. Funct. Program. 21, 4-5 (Sept. 2011), 333–412. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Phillip Wadler and Stephen Blott. 1989. How to Make Ad-hoc Polymorphism Less Ad Hoc. In Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’89). ACM, New York, NY, USA, 60–76. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Stephanie Weirich, Dimitrios Vytiniotis, Simon Peyton Jones, and Steve Zdancewic. 2011. Generative Type Abstraction and Type-level Computation. In Proceedings of the 38th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’11). ACM, New York, NY, USA, 227–240. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Jeremy Yallop. 2017. Staged Generic Programming. Proc. ACM Program. Lang. 1, ICFP, Article 29 (Aug. 2017), 29 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Brent A. Yorgey, Stephanie Weirich, Julien Cretin, Simon Peyton Jones, Dimitrios Vytiniotis, and José Pedro Magalhães. 2012. Giving Haskell a Promotion. In Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI ’12). ACM, New York, NY, USA, 53–66. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Generic deriving of generic traversals

        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

        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!