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.
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!
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.
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.
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.
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.