Getting at a zip code

Given a Customer, we can obviously use function composition to get their zip:

custZip ::Customer->ZipcustZip = addrZip . custAddress

Unfortunately, we lack a "good" facility for updating records. Let's see what that means.

Setting a zip code

We need to modify a zip code, but we're working in a pure language, so clearly a "zip code setter" is going to be a function that returns a new value that is identical to the previous value except for the zip.

setAddrZip ::Zip->Address->Address

If we have a new Address and we want to "modify" a Customer, we need a similar function:

Going backwards

We can use the fact that we can pattern match against nearby elements on both sides of our current focus to perform useful operations that need local context, e.g. sliding window algorithms, convolutions, etc.

Conversion back to a list

What should this function look like?

More general zippers

The ideas of differentiating data structures and zippers can be generalized to other recursive data structures, e.g. trees.