Hacker News new | ask | show | jobs
by kmelva 3045 days ago
> I'm currently working on a little utility library for editing rich text with Haskell and I've used the continuation monad to automatically derive a zipper for my data structure.

Could you go into more detail about this?

1 comments

Sure... most people familiar with zippers know that it can be thought of as the algebraic derivative the underlying type.

What’s perhaps less known is that this is the same as ‘differentiating’ the traversal of the data type.

The continuation monad is a sort of ‘derivative’ of a computation in that it nearly captures the ‘infinitesmal’ difference between two steps in a computation.

If your computation is the traversal of your tree, list, or text markup, then you can make a zipper from that without having to declare new data structures. This is isomorphic to declaring your own data structure. Its only advantage is convenience (that I know of at least).

Oleg Kiselyov goes into great detail with this idea and has lots of example code: http://okmij.org/ftp/continuations/zipper.html

Thanks for the answer, it'll keep me busy for a week or two!