skip to main content
research-article
Open Access

What you needa know about Yoneda: profunctor optics and the Yoneda lemma (functional pearl)

Published:30 July 2018Publication History
Skip Abstract Section

Abstract

Profunctor optics are a neat and composable representation of bidirectional data accessors, including lenses, and their dual, prisms. The profunctor representation exploits higher-order functions and higher-kinded type constructor classes, but the relationship between this and the familiar representation in terms of "getter" and "setter" functions is not at all obvious. We derive the profunctor representation from the concrete representation, making the relationship clear. It turns out to be a fairly direct application of the Yoneda Lemma, arguably the most important result in category theory. We hope this derivation aids understanding of the profunctor representation. Conversely, it might also serve to provide some insight into the Yoneda Lemma.

Skip Supplemental Material Section

Supplemental Material

a84-boisseau.webm

webm

80.1 MB

References

  1. Theodor Adorno. 1956. Fragment über Musik und Sprache. Reprinted in Gesammelte Schriften, Band 16: Musikalische Schriften I–III, Suhrkamp Verlag, 1978, p251–256.Google ScholarGoogle Scholar
  2. Kazuyuki Asada. 2010. Arrows are Strong Monads. In Mathematically Structured Functional Programming. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Alexey Avramenko. 2017. Yoneda and Coyoneda Trick. (April 2017). https://medium.com/@olxc/ yoneda- and- coyoneda- trick- f5a0321aeba4 .Google ScholarGoogle Scholar
  4. Steve Awodey. 2006. Category Theory. Oxford University Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Roland Backhouse. 2003. Program Construction: Calculating Implementations from Specifcations. Wiley. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. F. Bancilhon and N. Spyratos. 1981. Update Semantics of Relational Views. ACM Trans. Database Syst. 6, 4 (Dec. 1981), 557–575. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Richard S. Bird. 1984. The Promotion and Accumulation Strategies in Transformational Programming. ACM Transactions on Programming Languages and Systems 6, 4 (Oct. 1984), 487–504. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Edsger W. Dijkstra. 1991. Why Preorders Are Beautiful. (June 1991). EWD1102; available from http://www.cs.utexas.edu/ ~EWD/ewd11xx/EWD1102.PDF .Google ScholarGoogle Scholar
  9. Wim Feijen. 2001. The Joy of Formula Manipulation. Inform. Process. Lett. 77 (2001), 89–96. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J. Nathan Foster, Michael B. Greenwald, Jonathan T. Moore, Benjamin C. Pierce, and Alan Schmitt. 2005. Combinators for Bidirectional Tree Transformations: A Linguistic Approach to the View Update Problem. In Principles of Programming Languages. ACM Press, 233–246. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Jeremy Gibbons. 2016. Free Delivery (Functional Pearl). In Haskell Symposium. ACM, 45–50. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Jeremy Gibbons. 2017. APLicative Programming with Naperian Functors. In European Symposium on Programming (Lecture Notes in Computer Science), Hongseok Yang (Ed.), Vol. 10201. Springer Berlin Heidelberg, 556–583.Google ScholarGoogle Scholar
  13. Jeremy Gibbons and Bruno César dos Santos Oliveira. 2009. The Essence of the Iterator Pattern. Journal of Functional Programming 19, 3,4 (2009), 377–402. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Oleg Grenrus. 2017. Affine Traversal. http://oleg.fi/gists/posts/2017- 03- 20- affine- traversal.htmlGoogle ScholarGoogle Scholar
  15. Peter Hancock. 2005. What is a Naperian Container? (June 2005). http://sneezy.cs.nott.ac.uk/containers/blog/?p=14 .Google ScholarGoogle Scholar
  16. Ralf Hinze and Daniel W. H. James. 2010. Reason Isomorphically!. In Workshop on Generic Programming, Bruno C. d. S. Oliveira and Marcin Zalewski (Eds.). ACM, 85–96. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. R. John Muir Hughes. 1986. A Novel Representation of Lists and Its Application to the Function ‘Reverse’. Inform. Process. Lett. 22 (1986), 141–144. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Mauro Jaskelioff and Russell O’Connor. 2015. A Representation Theorem for Second-Order Functionals. Journal of Functtional Programming 25 (2015).Google ScholarGoogle Scholar
  19. Edward Kmett. 2015. profunctor library, Version 5. https://hackage.haskell.org/package/profunctors- 5Google ScholarGoogle Scholar
  20. Edward Kmett. 2018. lens library, Version 4.16. https://hackage.haskell.org/package/lens- 4.16Google ScholarGoogle Scholar
  21. Tom Leinster. 2000. The Yoneda Lemma: What’s It All About? (Oct. 2000). http://www.maths.ed.ac.uk/~tl/categories/ yoneda.ps .Google ScholarGoogle Scholar
  22. Saunders Mac Lane. 1971. Categories for the Working Mathematician. Springer-Verlag.Google ScholarGoogle Scholar
  23. Oleksandr Manzyuk. 2013. Co-Yoneda Lemma. (Jan. 2013). https://oleksandrmanzyuk.wordpress.com/2013/01/18/ co- yoneda- lemma/ .Google ScholarGoogle Scholar
  24. Kazutaka Matsuda and Meng Wang. 2015. Applicative Bidirectional Programming with Lenses. In International Conference on Functional Programming, Kathleen Fisher and John H. Reppy (Eds.). ACM, 62–74. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Shoukei Matsumoto. 2018. I Clean, Therefore I Am. The Guardian (5th January 2018). https://www.theguardian.com/ commentisfree/2018/jan/05/buddhist- monk- cleaning- good- for- you .Google ScholarGoogle Scholar
  26. Guerino Mazzola. 2002. The Topos of Music. Birkhäuser.Google ScholarGoogle Scholar
  27. Conor McBride and Ross Paterson. 2008. Applicative Programming with Effects. Journal of Functional Programming 18, 1 (2008), 1–13. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Bartosz Milewski. 2017a. Profunctor Optics: The Categorical Approach. https://www.youtube.com/watch?v=l1FCXUi6Vlw . Keynote at Lambda World conference, Cadiz.Google ScholarGoogle Scholar
  29. Bartosz Milewski. 2017b. Profunctor Optics: The Categorical View. (July 2017). https://bartoszmilewski.com/2017/07/07/ profunctor- optics- the- categorical- view/ .Google ScholarGoogle Scholar
  30. Max New. 2017. Closure Conversion as CoYoneda. (Aug. 2017). http://prl.ccs.neu.edu/blog/2017/08/28/ closure- conversion- as- coyoneda/ .Google ScholarGoogle Scholar
  31. Russell O’Connor. 2014. Mainline Profunctor Hierarchy for Optics. http://r6research.livejournal.com/27476.htmlGoogle ScholarGoogle Scholar
  32. Russell O’Connor. 2015a. Grate: A new kind of Optic. https://r6research.livejournal.com/28050.htmlGoogle ScholarGoogle Scholar
  33. Russell O’Connor. 2015b. mezzolens library, Version 0. https://hackage.haskell.org/package/mezzolens- 0Google ScholarGoogle Scholar
  34. Matthew Pickering, Jeremy Gibbons, and Nicolas Wu. 2017. Profunctor Optics: Modular Data Accessors. The Art, Science, and Engineering of Programming 1, 2 (2017), Article 7.Google ScholarGoogle Scholar
  35. Dan Piponi. 2006. Reverse Engineering Machines with the Yoneda Lemma. (Nov. 2006). http://blog.sigfpe.com/2006/11/ yoneda- lemma.html .Google ScholarGoogle Scholar
  36. Emily Riehl. 2016. Category Theory in Context. Dover Publications. Available from http://www.math.jhu.edu/~eriehl/ context.pdf .Google ScholarGoogle Scholar
  37. Mike Stay. 2008. The Continuation Passing Transform and the Yoneda Embedding. (Jan. 2008). https://golem.ph.utexas.edu/ category/2008/01/the_continuation_passing_trans.html .Google ScholarGoogle Scholar
  38. Perdita Stevens. 2010. Bidirectional Model Transformations in QVT: Semantic Issues and Open Questions. Software and System Modeling 9, 1 (2010), 7–20.Google ScholarGoogle ScholarCross RefCross Ref
  39. Paul Valéry. 1937. Leçon Inaugurale du Cours de Poétique du Collège de France. Reprinted in Variété V, Gallimard, 1944, p295–322.Google ScholarGoogle Scholar
  40. Twan van Laarhoven. 2009. CPS-Based Functional References. (July 2009). http://www.twanvl.nl/blog/haskell/ cps- functional- referencesGoogle ScholarGoogle Scholar
  41. Burghard von Karger. 2002. Temporal Algebra. In Algebraic and Coalgebraic Methods in the Mathematics of Program Construction (Lecture Notes in Computer Science), Roland Backhouse, Roy Crole, and Jeremy Gibbons (Eds.), Vol. 2297. Springer-Verlag, 310–386. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Philip Wadler. 1987. The Concatenate Vanishes. (Dec. 1987). University of Glasgow. Revised November 1989.Google ScholarGoogle Scholar

Index Terms

  1. What you needa know about Yoneda: profunctor optics and the Yoneda lemma (functional pearl)

                  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

                  • Published in

                    cover image Proceedings of the ACM on Programming Languages
                    Proceedings of the ACM on Programming Languages  Volume 2, Issue ICFP
                    September 2018
                    1133 pages
                    EISSN:2475-1421
                    DOI:10.1145/3243631
                    Issue’s Table of Contents

                    Copyright © 2018 Owner/Author

                    This work is licensed under a Creative Commons Attribution International 4.0 License.

                    Publisher

                    Association for Computing Machinery

                    New York, NY, United States

                    Publication History

                    • Published: 30 July 2018
                    Published in pacmpl Volume 2, Issue ICFP

                    Permissions

                    Request permissions about this article.

                    Request Permissions

                    Check for updates

                    Qualifiers

                    • research-article

                  PDF Format

                  View or Download as a PDF file.

                  PDF

                  eReader

                  View online with eReader.

                  eReader