Jump to ratings and reviews
Rate this book

Optics By Example

Rate this book
A comprehensive example-driven guide to optics. Examples in Haskell, but adaptable to other languages.

Become a data-manipulation wizard using optics to manipulate data!

This book takes you from beginner to advanced using Lenses, Traversals, Prisms, and more!

420 pages, ebook

First published December 11, 2019

7 people are currently reading
93 people want to read

About the author

Chris Penner

1 book3 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
16 (51%)
4 stars
11 (35%)
3 stars
1 (3%)
2 stars
3 (9%)
1 star
0 (0%)
Displaying 1 - 7 of 7 reviews
9 reviews1 follower
August 19, 2021
I came in not knowing how to focus, came out knowing how to focus.
Profile Image for Sandy Maguire.
Author 3 books202 followers
May 21, 2020
Disclaimer: Chris is a friend of mine.

This is an accessible book that introduces people to optics. It starts slowly and builds up to all sorts of insane pieces of technology which are frankly unbelievably powerful. It's rather inspiring what can be done by optics, though I'm not convinced I could write or read an expression using them on my first try. I learned a lot going through this book, and might reach more for optics the next time I do a big data transformation (though I fear it might be write-only code!)

While I liked this book, a good deal of the prose felt _too_ informal; a good deal of the type errors and signatures are described as "scary," and the examples reach too often for TV pop culture references that didn't seem relevant. All in all these are minor complaints, and the information content is more than enough to make up for it.
Profile Image for Matvey Aksenov.
71 reviews8 followers
May 3, 2023
So, I expected a lot more from this book, such as actually involved examples
of using lenses in the real world. What I got instead was this:

-- Get a list of all Integers in a sentence
>>> "It's True that I ate 3 apples and 5 oranges" ^.. worded . _Show :: [Int]
[3 , 5]

I'm pretty sure that no one will ever do anything like this in any setting.
So what's the point?

There was also a persistent feeling that maybe the author should at some point explain
how Van Laarhoven lenses (or any kind of lenses, really) work mechanically, but I guess
I'm not pragmatic™ enough. In fact, there was no discussion of pros and cons of different formulations whatsoever, although the author hints a couple times that profunctor lenses
are actually superior.

Honestly, just spending some time reading lens Haddock documentation is probably more
useful than this. Such a dissapointment!
Profile Image for Hugo Vilela.
2 reviews1 follower
November 6, 2025
A brilliant, pragmatic intro to optics.

Too many tutorials get lost in the theory (what’s a profunctor and who tf is Van Laarhoven) before you even know why you should care. Chris does the opposite: he shows you how incredibly useful optics are with little to no theory.

With that said, a last chapter about the different optics implementations and theory would be very welcome.
2 reviews
July 1, 2020
I know a bit of Haskell including some advanced topics but whenever I tried to approach lenses using tutorials hackage and youtube I was hopelessly confused by diabolical type complexity and size of it.
"Optics by example" takes a very different approach: instead of intimidating the reader with Profunctors , Rank-3 polymorphic types etc. it teaches to recognize situations where different types of optics shine (they are endless! because optics are so general-purpose) and gradually helps to build intuition about how they compose with each other. And it does this very well! At least much better than anything I was able to find up to date.
Yes, after reading the book I still have rather vague idea how exactly optics work under the hood and struggle to read many function signatures. But that's OK because I'm much more confident in using the library and black-magic type-safety still makes sure that code is sensible.
Profile Image for 0xd34df00d.
45 reviews8 followers
August 22, 2024
As usual, it depends on the expectations. As a practical introduction to optics, their types, the plethora of operators, and so on, and overcoming the usual lens-aversion one might get looking at Control.Lens.Operators, it's a good book. As something describing the theoretical foundations (what's van Laarhoven encoding, how it works with the simplest lenses, why do optics compose and require the constraints that they do, or one might expect at least to work out the usual substitutions with the Identity and Const functors), it's lacking. But that wasn't in the scope of this book anyway, I guess.
Profile Image for molty cheese.
5 reviews5 followers
July 19, 2020
Too verbose, doesn't touch on implementation

If you want a book which will informally lead you through lens API and provide some (often syntactic) examples, then you found one.
But if you are here to understand underlying implementation and why things work the way they do, then you would be in for a surprise.
The book never even touched on why `Lens` has a `Functor` constraint and how nicely different `Functor`s can be used to get and set a value in the structure.
Displaying 1 - 7 of 7 reviews

Can't find what you're looking for?

Get help and learn more about the design.