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.
Supplemental Material
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Lennart Augustsson. 2018. geniplate-mirror-0.7.6 library. http://hackage.haskell.org/package/geniplate-mirror-0.7.6Google Scholar
- 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 Scholar
Digital Library
- Maximilian C. Bolingbroke. 2011. Constraint Kinds for GHC. http://blog.omega-prime.co.uk/2011/09/10/ constraint-kinds-for-ghc/Google Scholar
- Joachim Breitner. 2018. Beyond correct and fast: Inspection Testing. CoRR abs/1803.07130 (2018). arXiv: 1803.07130 http://arxiv.org/abs/1803.07130Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Mauro Jaskelioff and Russell O’Connor. 2015. A Representation Theorem for Second-Order Functionals. Journal of Functional Programming 25, e13 (2015).Google Scholar
Cross Ref
- Edward Kmett. 2018. lens-4.16 library. https://hackage.haskell.org/package/lens-4.16Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- José Pedro Magalhães. 2012. Optimisation of generic programs through inlining. In Symposium on Implementation and Application of Functional Languages. Springer, 104–121.Google Scholar
- 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 Scholar
- Conor McBride and Ross Paterson. 2008. Applicative programming with effects. Journal of functional programming 18, 1 (2008), 1–13. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- Russell O’Connor. 2011. Functor is to Lens as Applicative is to Biplate: Introducing Multiplate. CoRR abs/1103.2841 (2011).Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- Matthew Pickering, Jeremy Gibbons, and Nicolas Wu. 2017. Profunctor Optics: Modular Data Accessors. Programming Journal 1, 2 (2017), 7.Google Scholar
Cross Ref
- 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 Scholar
Digital Library
- Twan van Laarhoven. 2009. CPS-Based Functional References. (July 2009). http://www.twanvl.nl/blog/haskell/ cps-functional-referencesGoogle Scholar
- Sjoerd Visscher and Li-yao Xia. 2018. one-liner-1.0 library. http://hackage.haskell.org/package/one-liner-1.0Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Jeremy Yallop. 2017. Staged Generic Programming. Proc. ACM Program. Lang. 1, ICFP, Article 29 (Aug. 2017), 29 pages. Google Scholar
Digital Library
- 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 Scholar
Digital Library
Index Terms
Generic deriving of generic traversals
Recommendations
Dependency-style generic haskell
Generic Haskell is an extension of Haskell that supports the construction of generic programs. During the development of several applications, such as an XML editor and compressor, we encountered a number of limitations with the existing (Classic) ...
Dependency-style generic haskell
ICFP '03: Proceedings of the eighth ACM SIGPLAN international conference on Functional programmingGeneric Haskell is an extension of Haskell that supports the construction of generic programs. During the development of several applications, such as an XML editor and compressor, we encountered a number of limitations with the existing (Classic) ...
A comparative study of language support for generic programming
OOPSLA '03: Proceedings of the 18th annual ACM SIGPLAN conference on Object-oriented programing, systems, languages, and applicationsMany modern programming languages support basic generic programming, sufficient to implement type-safe polymorphic containers. Some languages have moved beyond this basic support to a broader, more powerful interpretation of generic programming, and ...






Comments