zipper

What is the Zipper data structure and should I be using it?

The question is simple: I cannot understand the Zipper data structure. My question is related to its uses with a Tree. I want to understand how can I change the tree node using zipper. And how not to copy the whole tree (or the most part of it). Please, clarify if I'm wrong with zipper. Maybe it cannot help with the tree update? Or, m...

Haskell: Creating Type Classes for Zippers

So I've been reading a bit about the Zipper pattern in Haskell (and other functional languages, I suppose) to traverse and modify a data structure, and I thought that this would be a good chance for me to hone my skills at creating type classes in Haskell, since the class could present a common traversal interface for me to write code to...

returning multiple values using clojure xml zipper

Lets suppose we have some XML like so: <a> <b> <c>text</c> <d> <e>text</e> <f> ... lots of cruft here .. </f> </d> </b> <b> ... </b> <!-- more b sub-trees --> </a> Now, looking through the samples in zip_filter/xml.clj, I've figured out how to get to single values that I'm intereste...

How well do zippers perform in practice, and when should they be used?

I think that the zipper is a beautiful idea; it elegantly provides a way to walk a list or tree and make what appear to be local updates in a functional way. Asymptotically, the costs appear to be reasonable. But traversing the data structure requires memory allocation at each iteration, where a normal list or tree traversal is just po...

Effects of changing a node in a binary tree

Suppose I want to change the orange node in the following tree. So, the only other change I'll need to make is in the left pointer of the green node. The blue node will remain the same. Am I wrong somewhere? Because according to this article (that explains zippers), even the blue node needs to be changed. Similarly, in this picture...

Postorder tree traversal with clojure.zip to edit nodes

I have a tree represented as a nested vector. I want to have a generalization of indexed for trees, showing the index of each node like this, (visit 42); => [0 42] (visit [6 7]); => [0 ; [[0 6] ; [1 7]]] The naive implementation would use clojure.zip directly (as already asked here) (defn visit [...

Zipper like data structure with more then one cursor

The Zipper data structure is great when one wants to traverse a tree and keep the current position, but what data structure one should use if they want to track more then one position? Let me explain with examples: Someone on the #haskell channel has told me that zippers are used in yi editor to represent the cursor position. This is...

Cleaner way to update nested structures

Say I have got following two case classes: case class Address(street: String, city: String, state: String, zipCode: Int) case class Person(firstName: String, lastName: String, address: Address) and the following instance of Person class: val raj = Person("Raj", "Shekhar", Address("M Gandhi Marg", ...

How do I format a tree so that it works with Clojure's zipper?

I am creating trees of s-expressions for a genetic programming problem, and need to alter parts of the trees during the evolution process. I came across the Clojure zipper function that seems like it should be perfect, but for the life of me I can't figure out how to use it. For example, say I create a zipper with (def zipped (zip/seq-...