Optics By Example

Chris Penner

I hope you’ll allow me to be the eccentric old wizard mentor in your journey, and that you’ll be as enamored and enticed with this new power as I once was.


The handler focuses elements, pure ignores them.


_Show technically fails this law! It normalizes the formatting of the string according to its Show instance, which isn’t allowed according to the law. In practice this isn’t usually a big deal, it’s close enough. The two values are equal with respect to their semantic meaning, so we’ll give it a pass, but if you find yourself failing any of the laws for your custom prism you’ll want to think carefully about whether your prism makes sense.


Once it was recognized that the lens library could provide a clean interface to this type of programming, Data.Data.Lens and Control.Lens.Plated were added to subsume the operations provided by these other libraries with an optics-based interface.