The reason why there are so many operators is because there is a scheme with three parts:
<<
to return the old value,<
to return the new value, neither to not return any intermediate value- The operator to apply, e.g.
+
. =
to "mutate" inside aMonadState
,~
to do a pure computation
This is how you end up with so many operators. I get that this is not necessarily explained that well, though.
Also, as elegant as this style of lenses is, I agree that the types are a bit weird, which makes then a bit tricky to lean and also can result in unhelpful error messages, so your point is well taken there.
I would argue that everything is being named for what it is, it's just that the mathematical definitions underlying the types are sufficiently subtle that it is not easy to look at them and immediately make the connection between what you are seeing and why it works. (I personally had to study them for a while before really understanding what was going on.) Additionally, the
lens
package is arguably not the best entry point because it makes you learn both the basic concepts and a full batteries-included library for working with them in every conceivably way at the same time, which can be so overwhelming that it becomes impossible to learn either of these things.The good news, though, is that the advantage of this style of lenses is that the types are inherently structural rather than nominal, which means that you can, for example, use the far simpler
microlens
package instead and still interoperate with code that uses thelens
package.I find it interesting that you are so passionate about elm. The impression that I got when I last played with it a few years ago is that it is a good introduction to functional program because it shows just how nice things can get when everything is pure, but that eventually one outgrows it and its simplicity feels far more constraining than useful. So the good news is that you never have to learn about things like lenses, but the bad news is that if you run into a problem that would be solved really well by them, then too bad. How much one cares about this kind of thing is a genuine matter of personal preference, though.