Functional Pearl: Scrap Your Zippers
Michael D. Adams · 2007
The “zipper” data type provides the ability for editing tree shaped data in a pure functional setting and has found many uses and applications. However the traditional zipper has two major limitations. First, requires a significant amount of boilerplate code to implement. Second, it can only operate on homogeneous data types. Data structures where there are multiple node types are beyond the range of what it can handle. The generic zipper developed in this paper solves both these issues while maintaining type safety. It does this by encoding the path to the current position in the type of the zipper and by keeping an abstract representation of the object being traversed The techniques used develop the generic zipper also prove to have uses for other problems which will be briefly explored.