Tuesday, December 21, 2010

Functional abstraction through data differentiation

The zipper and the notion of data differentiation is a key to "higher level" architecture of functional programs.

Here is an example. Suppose we want to design a very simple graphical editor. Have a container that contains the recordings of the users editing; Could be as simple as "mouse down" "move mouse" and "mouse up" commands in sequences. Now a selection on this container would return two containers: the original one with "holes" where the selected material was taken out, the selection containing the content of the "holes". Reassembling the two together again brings up back to the original data. If instead we transform the selected sub-set and then reassemble the the two, we get something new. Try it out, it is a simple concept that goes very far in its usefulness.

No comments: