Compositionality

The open-access journal for the mathematics of composition

Profunctor Optics, a Categorical Update

Bryce Clarke1, Derek Elkins, Jeremy Gibbons2, Fosco Loregian3, Bartosz Milewski4, Emily Pillmore, and Mario Román2,3

1Macquarie University, School of Mathematics and Physical Sciences, New South Wales, NSW2109, Australia
2University of Oxford, Department of Computer Science, 7 Parks Rd, Oxford OX1 3QG, United Kingdom
3Tallinn University of Technology, Department of Software Sciences, Ehitajate tee 5, 19086 Tallinn, Estonia
4Programming Café

ABSTRACT

Optics are bidirectional data accessors that capture data transformation patterns such as accessing subfields or iterating over containers. Profunctor optics are a particular choice of representation supporting modularity, meaning that we can construct accessors for complex structures by combining simpler ones. Profunctor optics have previously been studied only in an unenriched and non-mixed setting, in which both directions of access are modelled in the same category. However, functional programming languages are arguably better described by enriched categories; and we have found that some structures in the literature are actually mixed optics, with access directions modelled in different categories. Our work generalizes a classic result by Pastro and Street on Tambara theory and uses it to describe mixed V-enriched profunctor optics and to endow them with V-category structure. We provide some original families of optics and derivations, including an elementary one for traversals. Finally, we discuss a Haskell implementation.

► BibTeX data

► References

[1] Faris Abou-Saleh, James Cheney, Jeremy Gibbons, James McKinna, and Perdita Stevens. Reflections on Monadic Lenses. In A List of Successes That Can Change the World - Essays Dedicated to Philip Wadler on the Occasion of His 60th Birthday, volume 9600 of "Lecture Notes in Computer Science", pages 1–31, Heidelberg, 2016. Springer. 10.1007/​978-3-319-30936-1_1.
https:/​/​doi.org/​10.1007/​978-3-319-30936-1_1

[2] Guillaume Boisseau. Understanding Profunctor optics: A Representation Theorem. Master's thesis, University of Oxford, 2017.

[3] Guillaume Boisseau and Jeremy Gibbons. What you needa know about Yoneda: Profunctor optics and the Yoneda Lemma (functional pearl). PACMPL, 2 (ICFP): 84:1–84:27, 2018. 10.1145/​3236779.
https:/​/​doi.org/​10.1145/​3236779

[4] Mario Cáccamo and Glynn Winskel. A Higher-Order Calculus for Categories. In Richard J. Boulton and Paul B. Jackson, editors, Theorem Proving in Higher Order Logics, 14th International Conference, TPHOLs 2001, Edinburgh, Scotland, UK, September 3-6, 2001, Proceedings, volume 2152 of Lecture Notes in Computer Science, pages 136–153. Springer, 2001. 10.1007/​3-540-44755-5_11.
https:/​/​doi.org/​10.1007/​3-540-44755-5_11

[5] Geoffrey Cruttwell and Michael Shulman. A unified framework for generalized multicategories. Theory and Applications of Categories, 24 (21): 580–655, 2010. 10.48550/​arXiv.0907.2460.
https:/​/​doi.org/​10.48550/​arXiv.0907.2460

[6] Brian Day. On Closed Categories of Functors. In Reports of the Midwest Category Seminar IV, pages 1–38, Heidelberg, 1970. Springer.

[7] Brian Day and Miguel Laplaza. On Embedding Closed Categories. Bulletin of the Australian Mathematical Society, 18 (3): 357–371, 1978.

[8] Ronald Fisher. The Use of Multiple Measurements in Taxonomic Problems. Annals of Eugenics, 7 (2): 179–188, 1936.

[9] Brendan Fong and Michael Johnson. Lenses and Learners. In James Cheney and Hsiang-Shang Ko, editors, Proceedings of the 8th International Workshop on Bidirectional Transformations co-located with the Philadelphia Logic Week, Bx@PLW 2019, Philadelphia, PA, USA, June 4, 2019, volume 2355 of CEUR Workshop Proceedings, pages 16–29. CEUR-WS.org, 2019. 10.48550/​arXiv.1903.03671.
https:/​/​doi.org/​10.48550/​arXiv.1903.03671

[10] Nathan Foster, Michael Greenwald, Jonathan Moore, Benjamin Pierce, and Alan Schmitt. Combinators for bi-directional tree transformations: A linguistic approach to the view update problem. In Proceedings of the 32nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2005, Long Beach, California, USA, January 12-14, 2005, pages 233–246, 2005. 10.1145/​1040305.1040325.
https:/​/​doi.org/​10.1145/​1040305.1040325

[11] Thomas Fox. Coalgebras and cartesian categories. Communications in Algebra, 4 (7): 665–667, 1976.

[12] Phil Freeman, Brian Marick, Lukas Heidemann, et al. Purescript Profunctor Lenses. Github https:/​/​github.com/​purescript-contrib/​purescript-profunctor-lenses, 2015–2019.
https:/​/​github.com/​purescript-contrib/​purescript-profunctor-lenses

[13] Neil Ghani, Jules Hedges, Viktor Winschel, and Philipp Zahn. Compositional Game Theory. In Proceedings of the 33rd Annual ACM/​IEEE Symposium on Logic in Computer Science, LICS 2018, Oxford, UK, July 09-12, 2018, pages 472–481, 2018. 10.1145/​3209108.3209165.
https:/​/​doi.org/​10.1145/​3209108.3209165

[14] John Hughes. Generalising Monads to Arrows. Science of Computer Programming, 37 (1-3): 67–111, 2000. 10.1016/​S0167-6423(99)00023-4.
https:/​/​doi.org/​10.1016/​S0167-6423(99)00023-4

[15] Bart Jacobs, Chris Heunen, and Ichiro Hasuo. Categorical Semantics for Arrows. Journal of Functional Programming, 19 (3-4): 403–438, 2009. 10.1017/​S0956796809007308.
https:/​/​doi.org/​10.1017/​S0956796809007308

[16] Mauro Jaskelioff and Russell O'Connor. A Representation Theorem for Second-Order Functionals. Journal of Functional Programming, 25, 2015. 10.1017/​S0956796815000088.
https:/​/​doi.org/​10.1017/​S0956796815000088

[17] Mauro Jaskelioff and Ondrej Rypacek. An Investigation of the Laws of Traversals. In Proceedings Fourth Workshop on Mathematically Structured Functional Programming, MSFP@ETAPS 2012, Tallinn, Estonia, 25 March 2012., pages 40–49, 2012. 10.4204/​EPTCS.76.5.
https:/​/​doi.org/​10.4204/​EPTCS.76.5

[18] Max Kelly. Basic Concepts of Enriched Category Theory. Reprints in Theory and Applications of Categories, 1 (10): 137, 2005a. Reprint of the 1982 original. Cambridge Univ. Press, Cambridge; MR0651714.

[19] Max Kelly. On the Operads of J. P. May. Reprints in Theory and Applications of Categories, 13 (1), 2005b.

[20] Edward Kmett. Lens library, version 4.16. Hackage https:/​/​hackage.haskell.org/​package/​lens-4.16, 2012–2018.
https:/​/​hackage.haskell.org/​package/​lens-4.16

[21] Paul Levy. Strong functors on many-sorted sets. Commentationes Mathematicae Universitatis Carolinae, 60 (4): 533–540, 2019.

[22] Fosco Loregian. (Co)end Calculus. London Mathematical Society Lecture Note Series. Cambridge University Press, 2021. 10.1017/​9781108778657.
https:/​/​doi.org/​10.1017/​9781108778657

[23] Saunders Mac Lane. Categories for the Working Mathematician. Graduate Texts in Mathematics. Springer New York, 1978. 10.1007/​978-1-4757-4721-8.
https:/​/​doi.org/​10.1007/​978-1-4757-4721-8

[24] Conor McBride and Ross Paterson. Applicative programming with effects. Journal of Functional Programming, 18 (1): 1–13, 2008. 10.1017/​S0956796807006326.
https:/​/​doi.org/​10.1017/​S0956796807006326

[25] Bartosz Milewski. Profunctor Optics: The Categorical View. https:/​/​bartoszmilewski.com/​2017/​07/​07/​profunctor-optics-the-categorical-view/​, 2017.
https:/​/​bartoszmilewski.com/​2017/​07/​07/​profunctor-optics-the-categorical-view/​

[26] Russell O'Connor. Grate: a New Kind of Optic. https:/​/​r6research.livejournal.com/​28050.html, 2015a.
https:/​/​r6research.livejournal.com/​28050.html

[27] Russell O'Connor. Mezzolens: Pure Profunctor Functional Lenses. Hackage https:/​/​hackage.haskell.org/​package/​mezzolens, 2015b.
https:/​/​hackage.haskell.org/​package/​mezzolens

[28] Frank Joseph Oles. A Category-Theoretic Approach to the Semantics of Programming Languages. PhD thesis, Syracuse University, 1982.

[29] Luke Palmer. Making Haskell Nicer for Game Programming. https:/​/​lukepalmer.wordpress.com/​2007/​07/​26/​making-haskell-nicer-for-game-programming/​, archived at https:/​/​web.archive.org/​web/​20141219182332/​http:/​/​lukepalmer.wordpress.com/​2007/​07/​26/​making-haskell-nicer-for-game-programming/​, 2007.
https:/​/​lukepalmer.wordpress.com/​2007/​07/​26/​making-haskell-nicer-for-game-programming/​

[30] Craig Pastro and Ross Street. Doubles for Monoidal Categories. Theory and Applications of Categories, 21 (4): 61–75, 2008.

[31] Matthew Pickering, Jeremy Gibbons, and Nicolas Wu. Profunctor Optics: Modular Data Accessors. Programming Journal, 1 (2): 7, 2017. 10.22152/​programming-journal.org/​2017/​1/​7.
https:/​/​doi.org/​10.22152/​programming-journal.org/​2017/​1/​7

[32] Emily Pillmore and Mario Román. Vitrea library, version 0.1.0.0. Hackage https:/​/​hackage.haskell.org/​package/​vitrea-0.1.0.0, Github https:/​/​github.com/​mroman42/​vitrea, 2019–2020.
https:/​/​hackage.haskell.org/​package/​vitrea-0.1.0.0

[33] Emily Pillmore and Mario Román. Profunctor optics: The categorical view. https:/​/​golem.ph.utexas.edu/​category/​2020/​01/​profunctor_optics_the_categori.html, 2020.
https:/​/​golem.ph.utexas.edu/​category/​2020/​01/​profunctor_optics_the_categori.html

[34] Mitchell Riley. Categories of optics. arXiv preprint arXiv:1809.00738, 2018.
arXiv:1809.00738

[35] Exequiel Rivas and Mauro Jaskelioff. Notions of Computation as Monoids. Journal of Functional Programming, 27, 2017. 10.1017/​S0956796817000132.
https:/​/​doi.org/​10.1017/​S0956796817000132

[36] Mario Román. Profunctor Optics and Traversals. Master's thesis, University of Oxford, 2019.

[37] Mario Román. Open Diagrams via Coend Calculus. Electronic Proceedings in Theoretical Computer Science, 333, Applied Category Theory 2020: 65–78, Feb 2021. ISSN 2075-2180. 10.4204/​eptcs.333.5.
https:/​/​doi.org/​10.4204/​eptcs.333.5

[38] David Spivak. Generalized lens categories via functors $\mathcal{C}^{\mathrm{op}} \to \mathsf{Cat}$. arXiv preprint arXiv:1908.02202, 2019. 10.48550/​arXiv.1908.02202.
https:/​/​doi.org/​10.48550/​arXiv.1908.02202
arXiv:1908.02202

[39] Perdita Stevens. Bidirectional Model Transformations in QVT: Semantic Issues and Open Questions. Software and Systems Modeling, 9 (1): 7–20, 2010. 10.1007/​s10270-008-0109-9.
https:/​/​doi.org/​10.1007/​s10270-008-0109-9

[40] Daisuke Tambara. Distributors on a tensor category. Hokkaido mathematical journal, 35 (2): 379–425, 2006.

[41] Twan van Laarhoven. CPS-based functional references. https:/​/​www.twanvl.nl/​blog/​haskell/​cps-functional-references, 2009a.
https:/​/​www.twanvl.nl/​blog/​haskell/​cps-functional-references

[42] Twan van Laarhoven. A non-regular data type challenge. https:/​/​www.twanvl.nl/​blog/​haskell/​non-regular1, 2009b.
https:/​/​www.twanvl.nl/​blog/​haskell/​non-regular1

[43] Sjoerd Visscher. Data.Category library, version 0.10. Hackage https:/​/​hackage.haskell.org/​package/​data-category, 2010–2020.
https:/​/​hackage.haskell.org/​package/​data-category

Cited by

On Crossref's cited-by service no data on citing works was found (last attempt 2024-03-01 13:43:56). On SAO/NASA ADS no data on citing works was found (last attempt 2024-03-01 13:43:57).