4 ms·
Wow, I love this. My impression is that Specter is (at least in main use cases) Haskell's lens package. But while lens is very inside-baseball (at least in the
by rtpg 11y ago
Wow, I love this. My impression is that Specter is (at least in main use cases) Haskell's lens package. But while lens is very inside-baseball (at least in the tutorials I read), this explanation describes an extremely useful principle.
Every language needs a lens/Specter. If you're spending a lot of time messing with data, this article will go directly to your heart.
- skratlo 11y agoExactly what I thought, either lens or zippers.
- tel 11y agoDefinitely more lens than zipper. If you think of a lens, in simple form, as a path into a structure then a zipper is a structure plus a path into itself. This constrains the form that a zipper can take. If you examine these paths on their own then you get into general "optics" which is where the lens type lives and where specter lives (it seems). In particular, we start talking about generalized folds and traversals.
- dj-wonk 11y agoI think https://www.fpcomplete.com/school/to-infinity-and-beyond/pick-of-the-week/basic-lensing https://www.fpcomplete.com/school/to-infinity-and-beyond/pic... does a nice job of explaining a lens: > At its simplest, a lens is a value representing maps between a complex type and one of its constituents. This map works both ways—we can get or "access" the constituent and set or "mutate" it. For this reason, you can think of lenses as Haskell's "getters" and "setters", but we shall see that they are far more powerful.