3 ms·
For the specific case of traversing objects (well, let's say data types), I think Haskell's lens library is the ultimate modern example. In fact, I think it ba
by tikhonj 13y ago
For the specific case of traversing objects (well, let's say data types), I think Haskell's lens library is the ultimate modern example. In fact, I think it basically covers everything he asked for in that section and more. It's quite a large library, for better or worse, so it really is complete.
People have called it a "jQuery for data types", and that isn't such a bad description. It allows you to uniformly interact with nested records (similar to objects), collections and variants (values chosen from a known set of possibilities--sum types).
It's systematic, modular and surprisingly powerful. Of course, like many powerful abstractions--including Haskell itself--it takes a bit of up-front effort to learn, but it's more than worth it.
- batgaijin 13y agocaaddr! cdaddr! cddadr! those are the first lines from the macbeth witches if my memory serves correctly.
- _pmf_ 13y agoLenses do one thing right, which is abstracting data access instead of abstracting data.
- jhickner 13y agoDoes lens have a succinct way to traverse a nested data structure where each node is a maybe? Lenses + Prisms (nicest way I know of in lens): nested ^? foo . _Just . bar . _Just . baz . _Just vs. the Maybe monad: foo >=> bar >=> baz $ nested
- mercurial 13y agoI think that's basically it. You can check out a great example of prisms in the lens-aeson article on FPComplete: https://www.fpcomplete.com/user/tel/lens-aeson-traversals-prisms https://www.fpcomplete.com/user/tel/lens-aeson-traversals-pr...
- tel 13y agoThat's the nicest I know as well. You could use `mapped` instead of `_Just` to make it more generic nested ^? foo . mapped . bar . mapped . baz . mapped Which is also a bit closer to the nature of `>=>` chaining. I actually really like the _Just descent since it makes some of the failure modes for this lens very explicit. And then it should always be said that the lens has setter properties that the `>=>` chain does not.