4 ms·
In a language like C, the dot '.' and the arrow '->' are used for access into structures - both for setting and retrieving values. I think intuitively about a l
by lindig 8y ago
In a language like C, the dot '.' and the arrow '->' are used for access into structures - both for setting and retrieving values. I think intuitively about a lens as a programmable dot which I can use to compose an access path. (You might have heard that the bind operator in a monad can be thought of as a programmable semicolon - this is similar.) This intuition might mean little if you haven't looked at lenses in more detail, but it does make sense once you have.
- mannykannot 8y agoThough these operators can be used in modifiable lvalue expressions, while lenses are (according to this article) pure functions.
- lindig 8y agoAs pointed out in this thread, a lens has to return the modified object as it can't update it as a side effect. That is the reason no universal dot-like lens operator exists in Haskell but it needs to be composed based on the data structures that it targets.
- mannykannot 8y agoWell, yes, but bear in mind that the absence of side effects is seen as a virtue in functional programming, and it is a point of view that I have considerable agreement with.