3 ms·
In Haskell, structures are immutable. You cannot set a member on a copy, because the copy is immutable too. You have to provide the new value to the constructor
by oever 8y ago
In Haskell, structures are immutable. You cannot set a member on a copy, because the copy is immutable too. You have to provide the new value to the constructor. The lenses are syntactic sugar to create a copy with only one member changed. It's not pretty nor efficient, but a result of having only immutable structures.
- zoul 8y agoYou make it sound like lenses are a sort of a crutch, but in my opionion they are not. The idea of having a first-class, composable way to “focus” on a part of a larger structure makes a lot of sense. And can be very pretty, too – see Swift’s key paths. That kind of type safety and simplicity is very appealing to me. As for efficiency, copying stuff usually means improved thread safety, so that’s win for me. Also, copy on write makes things often much more efficient in practice.