3 ms·
As soon as I heard about this formulation back in 2012 or so I concluded that this particular structure was going to be foundational in Haskell and potentially
by mightybyte 4y ago
As soon as I heard about this formulation back in 2012 or so I concluded that this particular structure was going to be foundational in Haskell and potentially the broader (purely) functional programming world. I agree with your intuition here with respect to that statement, but this case is an exception to that heuristic. I would say that these lenses are the purely functional equivalent to pointers in C. These lenses are type-safe functional pointers that are composable! This lens formulation is much more powerful than the naive lens formulations that came before it and it admits a number of just as powerful related abstractions such as prisms, traversals, etc.
Historically I have been pretty skeptical about adopting flavor-of-the-week flashy abstractions in the Haskell ecosystem for use in production code, usually preferring to lean on ADTs and pure functions for their simplicity and power. But lenses are essential. They are the fundamental building blocks for accessing and modifying ADTs. You don't have to understand the complicated type wizardry to use them. They're particularly useful for drilling deep into arbitrary JSON structures. See a reddit comment of mine for some examples: https://old.reddit.com/r/haskell/comments/792nl4/clojure_vs_the_static_typing_world_haskell_in/doyyakq/ https://old.reddit.com/r/haskell/comments/792nl4/clojure_vs_...
For more on this, see this excellent video "The Unreasonable Effectiveness of Lenses for Business Applications": https://www.youtube.com/watch?v=T88TDS7L5DY&t=1204s https://www.youtube.com/watch?v=T88TDS7L5DY&t=1204s
- dmix 4y agoAre lenses used much in OCaml the way they are in Haskell?