Chapter 15. Zippers

While Haskell’s purity comes with a whole bunch of benefits, it makes us tackle some problems differently than we would in impure languages.

Because of referential transparency, one value is as good as another in Haskell if it represents the same thing. So, if we have a tree full of fives (high fives, maybe?), and we want to change one of them into a six, we must have some way of knowing exactly which five in our tree we want to change. We need to know where it is in our tree. In impure languages, we could just note where the five is located in memory and change that. But in Haskell, one five is as good as another, so we can’t discriminate based on their location in memory.

We also can’t really change anything. When we say that ...

Get Learn You a Haskell for Great Good! now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.