Re:Dhall: A Gateway Drug to Haskell
by Karrot_Kream on Tuesday June 07, 2022 @09:32PM
(#31662236)
The Lens library sucks even if you're fluent in advanced math and Haskell. In practice when I have to use Lens (usually with JSON), I just code golf it until it works because it's so damn impenetrable.
I couldn’t agree with this opinion less - lens is incredibly elegant, and very consistent. It is a DSL, and you need to spend some time learning the domain, but once you do you’ll find it hard to live without it. If that’s the way you use the library then you haven’t spent any time to learn how to use it.
If you apply `_1` to `set` then it specializes to `set _1 :: a -> (a, b) -> (a, b)`.
Yes its confusing. It sometimes helps to give longer variables:
_1 :: Lens' (fst, snd) fst
set :: Lens' structure focus -> focus -> structure -> structure
set _1 :: fst -> (fst, snd) -> (fst, snd)
You are bumping up against the severe amount of polymorphism at play in the lens library. This makes it hard to build a mental model but is a tremendous source of expressiveness and utility.
To summarize, Haskell documentation communication is biased against linguistically clear explanations and towards mathematically precise, symbolic "explanation", and those who are used to unnecessarily struggling with the latter style due to their math background are more likely to "make it".