I got interested in lenses because I was looking for a better way to handle state in front end applications (ELM Architecture and Redux were nice ideas but using Elm or PureScript face some management obstacles and Redux lacks types and more explicit composition). Studying them I found profunctors and the more I knew about them both the more interested I was. Now I look at optics as profunctor transformations that can be applied to a much wider menu of use cases than data accessors for nested structures.
This Gist is my collection of shortcuts to several resources here and there that either I consult frequently or I recommend frequently.
Optics as profunctor transformations are in correspondence with the profunctorial restrictions and have the following type definition:
type Optical p s t a b = p a b -> p s t
Restriction | Optic |
---|---|
Profunctor | Iso |
Strong/Cartesian | Lens |
Choice/Co-Cartesian | Prism |
Co-Choice | Coprism |
(Strong, Choice)/Wander | AffineTraversal |
Lenses are commonly represented with co-algebras, this representation is also known as Van Laarhoven and was introduced in Van Laarhoven [2009]
type Lens a b = forall f. Functor f => (b -> f b) -> (a -> f a)
- 2018 Another Look Through Optics
- 2018 Handling Errors with Profunctor Optics
- 2019 Generalizing functions with Profunctors
- 2019 James Phillips, Alphabet Soup: Lensing, for free
- 2019 Philip Zucker, Lens as a Divisibility Relation: Goofin’ Off With the Algebra of Types
- 2018 Guillaume Boisseau, Jeremy Gibbons, What You Needa Know about Yoneda
- 2016 Phil Freeman, Fun with Profunctors. Although a bit long, this video worths the time spent watching it entirely.
- 2017 Oleg Grenrus Glasery
- 2017 Oleg Grenrus Affine Traversal
- 2013 Simon Peyton Jones, Lenses: Compositional Data Access and Manipulation. Video presentation of Lenses and Prisms with nice examples. One of the best introductions to optics for newcomers.
- 2008 Edward Kmet Deriving Strength from Laziness
- 2009 Twan van Laarhoven CPS based functional references. This short post introuces what is now known as the Van Laarhoven (co-algebra) form for lenses.
- 2018 Brian Marick Lenses for the Mere Mortal: PureScript Edition. A pragmatic introudction to Lenses, Prisms and Traversals. It's focused on data accesors but goes to the point without getting into implementation details. Code examples are in PureScript but will be easy to read for any developer.
- 2017 Bartosz Milewski, Profunctor Optics: The Categorical View
- 2015 Russell O'Connor Grate: A new kind of Optic
- 2014 Russell O'Connor Mainline Profunctor Heirarchy for Optics
- 2011 Russell O'Connor Functor is to Lens as Applicative is to Biplate
- 2017 Matthew Pickering, Jeremy Gibbons, and Nicolas Wu, Profunctor Optics
- 2011 Dan Piponi Profunctors in Haskell
- 2018 Gabriel Riba Faura Easier lenses, Profunctor based, with the Mezzolens library
- 2018 nLab Profunctor. A categorical summary of the concept of Profunctor.
- 2018 Jesús López-González (@jeslg) Don't Fear the Profunctor Optics!
- Lens: Lenses, Folds and Traversals Probably the most used of all optics libraries.
- Official web page: http://lens.github.io/
- Hackage: http://hackage.haskell.org/package/lens
- GitHub: https://github.com/ekmett/lens/
- Profunctor
- Mezzolens A profunctor optic library
- Optics
- Github: https://leanpub.com/lenses
- Monocle This library offers optics in their simple version:
a -> s
instead of its regular profunctor signaturep a b -> p s t
. They actually have the full version but seems it's only used internally.
- Ramda Although not only an optics library but a functional toolkit for JS.
- Lens.ts
- Telescope.js Although not an optics library, includes a simple lens implementation used in a state management context. (Disclosure: I co-authored this library)