Applied Deliberation

Assorted Adventures of Sampsa Kiiskinen

Week 8 Exercises

This week we will look at zippers and their interesting connections to calculus.

Exercise 1

Zippers are essentially suspended traversals over data structures. They are very useful for long-running programs like user interfaces, because it is often necessary to momentarily interrupt normal operation to interact with the user or communicate over the network. What makes zippers particularly interesting is that they can be derived mechanically by differentiating the corresponding types.

Differentiate the following types to obtain the types of their zippers.

  1. Derivative of Maybe a.
  2. Derivative of Join (,) a.
  3. Derivative of [] a.
  4. Derivative of Stream a from the streams package.
  5. Derivative of Tree a from the binary-tree package.
  6. Derivative of Tree a from the containers package.

We will need these to do exercise 2 as well.


Exercise 2

Define navigation functions for the zippers of the following types. That is, for each type A with a zipper of type ZA, implement a function of type MonadThrow m => A -> m ZA that tries to create a zipper and functions of type MonadThrow m => ZA -> m ZA that try to move the zipper around.

  1. Zipper for Maybe a.
  2. Zipper for Join (,) a.
  3. Zipper for [] a.
  4. Zipper for Stream a from the streams package.
  5. Zipper for Tree a from the binary-tree package.
  6. Zipper for Tree a from the containers package.

The Monad constraint should allow you to use do notation to ensure your navigation functions can really reach any position.


Exercise 3

Build whatever you want and I will grade it based on how cool it is and how well you managed to utilize what you have learned on this course.

If you are out of ideas, the following modules may provide some inspiration.