Questions tagged [zipper]

A zipper is a technique of representing a data structure so that it is convenient for traversal and updates, especially in pure functional languages.

A zipper is a technique of representing an aggregate data structure so that it is convenient for writing programs that traverse the structure arbitrarily and update its contents, especially in purely functional programming languages.

The basic idea is that an existing list- or tree-like data structure is augmented with a representation of a "focus" on a single item in the tree in a way that permits efficient lookups and updates at the focus point.

A simple example is a zipper for a list, consisting of a pair of two lists. For example, the position of 3 in the list (1,2,3,4,5) is represented by the pair ((2,1),(3,4,5)). To insert a new item or replace 3 with another item with this representation can be done in constant time since 3 is at the head of the second list of the pair. Traversing the list is similarly easy: remove the head of either list and cons it with the other list.

You can read more about zipper in Haskell in the Haskell Wikibook.

126 questions
14
votes
4 answers

VSCode not recognizing includes from includepath

I am having an issue where VSCode will recognize my include of zipper.h and then out of nowhere flip on me and tell me that there is no such file or directory. I am not sure if this is an issue with my code or includes or vs…
SomeSimpleton
  • 350
  • 1
  • 2
  • 12
13
votes
1 answer

Zipper to iterate over list in Scala

This is a follow-up to my previous question. I can use an iterator, fold, zip, foreach and others to iterate over a list in Scala. Now I wonder if there are use cases where Zipper is most appropriate. Suppose I need read-only access without…
Michael
  • 41,026
  • 70
  • 193
  • 341
13
votes
2 answers

Making a grid-like data type in haskell

Problem I've been wondering how this could be done efficiently for a while, but for some reason I have been unable to do it. I need to model a rectangular grid, where each field contains some data. I need to access it via a zipper, where my focus is…
Undreren
  • 2,811
  • 1
  • 22
  • 34
10
votes
1 answer

Locally editing a purely functional tree

Let's define a tree T: A / \ B C / \ D E Let's say a new node is added to E, yielding T': A / \ B C / \ D E \ G In a mutable language this is an easy task - just update E's children and we're done. However,…
Philip Kamenarsky
  • 2,757
  • 2
  • 24
  • 30
10
votes
1 answer

Derivatives of data structures in Agda

I am currently implementing derivatives of regular data structures, in Agda, as presented in the One-Hole Context paper by Conor McBride [5]. In implementing it straight out of the OHC paper, which has also been done by Löh & Magalhães [3,4], we are…
N. Brett
  • 171
  • 5
9
votes
1 answer

Zipper vs. iterator for walking over a list or tree

Suppose I need to walk over a list or tree to read (but not modify) the data. I can use either an iterator or a Zipper. Does Zipper have any advantages aside from immutability in this case?
Michael
  • 41,026
  • 70
  • 193
  • 341
9
votes
2 answers

Clojure Zipper of nested Maps repressing a TRIE

How can I create a Clojure zipper for a TRIE, represented by nested maps, were the keys are the letters.? Something like this: {\b {\a {\n {\a {\n {\a {'$ '$}}}}}} \a {\n {\a {'$ '$}}}} Represents a trie with 2 words 'banana' and 'ana'. (If…
0xMG
  • 93
  • 5
8
votes
0 answers

immutable functional data structure to represent graphs

I (almost) fully understand the Zipper data structure for trees. However, in some publications I saw hints that it is also possible to use the Zipper idea to create immutable functional data structure for arbitrary graphs (which might have cycles as…
vasaki
  • 205
  • 2
  • 8
8
votes
1 answer

Zipper data structure for graphical model editor

I'm writing a graphical editor for a "model" (i.e. a collection of boxes and lines with some kind of semantics, such as UML, the details of which don't matter here). So I want to have a data structure representing the model, and a diagram where an…
Paul Johnson
  • 17,438
  • 3
  • 42
  • 59
8
votes
2 answers

How to navigate up inside a HUET Zipper

I'm reading Huet Zipper, I cannot understand the go_up method: let go_up (Loc(t,p)) = match p with Top -> failwith "up of top" | Node(left,up,right) -> Loc(Section((rev left) @ (t::right)),up);; The full source of other types definitions can be…
Sawyer
  • 15,581
  • 27
  • 88
  • 124
7
votes
1 answer

Type errors with Existential types in Haskell

I am struggling with existential types in my program. I think I'm trying to do something very reasonable however I cannot get past the typechecker :( I have a datatype that sort of mimics a Monad data M o = R o | forall o1. B (o1 -> M o) (M o1) Now…
Anupam Jain
  • 7,851
  • 2
  • 39
  • 74
7
votes
1 answer

Why does the Clojure zipper implementation use different types and data structures from Huet's zipper?

I'm comparing Huet's original paper with Clojure's implementation and trying to figure out why the changes were made. I'm a Clojure novice, so if I'm wrong on my interpretation of the Clojure code, please correct me. In Huet's paper, the type of a…
ceridwen
  • 550
  • 2
  • 5
  • 14
7
votes
1 answer

Find location of node in tree using Clojure zippers

I have a tree of an unknown structure. First, I want to find a node containing a string of text, "Something". Then, after identifying the string's location in the tree, I want to update a different node relative to the string's location. The data is…
KendallB
  • 4,799
  • 4
  • 19
  • 21
6
votes
2 answers

Zipping and downloading Amazon S3 bucket files and folders in Laravel

Is there a way to zip and download files and folders which are in Amazon S3 bucket, together in Laravel? I Want to zip the three folders and one file in the picture together and download it
Tauseef Mamun
  • 126
  • 1
  • 3
  • 11
6
votes
0 answers

Zippers in the wild

I am currently searching for implementations of Huet's Zipper ``in the wild''. So far, I have found: The agda compiler (correct me if I'm wrong) uses the zipper for the eliminator of call-by-need evaluations, filling out information as it…
N. Brett
  • 171
  • 5
1
2
3
8 9