<s>
A	O
zipper	B-Application
is	O
a	O
technique	O
of	O
representing	O
an	O
aggregate	O
data	B-General_Concept
structure	I-General_Concept
so	O
that	O
it	O
is	O
convenient	O
for	O
writing	O
programs	O
that	O
traverse	O
the	O
structure	O
arbitrarily	O
and	O
update	O
its	O
contents	O
,	O
especially	O
in	O
purely	O
functional	O
programming	O
languages	O
.	O
</s>
<s>
The	O
zipper	B-Application
was	O
described	O
by	O
Gérard	O
Huet	O
in	O
1997	O
.	O
</s>
<s>
It	O
includes	O
and	O
generalizes	O
the	O
gap	B-Data_Structure
buffer	I-Data_Structure
technique	O
sometimes	O
used	O
with	O
arrays	O
.	O
</s>
<s>
The	O
zipper	B-Application
technique	O
is	O
general	O
in	O
the	O
sense	O
that	O
it	O
can	O
be	O
adapted	O
to	O
lists	O
,	O
trees	B-Application
,	O
and	O
other	O
recursively	O
defined	O
data	B-General_Concept
structures	I-General_Concept
.	O
</s>
<s>
Such	O
modified	O
data	B-General_Concept
structures	I-General_Concept
are	O
usually	O
referred	O
to	O
as	O
"	O
a	O
tree	O
with	O
zipper	B-Application
"	O
or	O
"	O
a	O
list	O
with	O
zipper	B-Application
"	O
to	O
emphasize	O
that	O
the	O
structure	O
is	O
conceptually	O
a	O
tree	O
or	O
list	O
,	O
while	O
the	O
zipper	B-Application
is	O
a	O
detail	O
of	O
the	O
implementation	O
.	O
</s>
<s>
A	O
layperson	O
's	O
explanation	O
for	O
a	O
tree	O
with	O
zipper	B-Application
would	O
be	O
an	O
ordinary	O
computer	O
filesystem	B-Application
with	O
operations	O
to	O
go	O
to	O
parent	O
(	O
often	O
cd	B-Application
..	I-Application
)	O
,	O
and	O
the	O
possibility	O
to	O
go	O
downwards	O
(	O
cd	B-Application
subdirectory	O
)	O
.	O
</s>
<s>
The	O
zipper	B-Application
is	O
the	O
pointer	O
to	O
the	O
current	O
path	O
.	O
</s>
<s>
Behind	O
the	O
scenes	O
the	O
zippers	B-Application
are	O
efficient	O
when	O
making	O
(	O
functional	O
)	O
changes	O
to	O
a	O
data	B-General_Concept
structure	I-General_Concept
,	O
where	O
a	O
new	O
,	O
slightly	O
changed	O
,	O
data	B-General_Concept
structure	I-General_Concept
is	O
returned	O
from	O
an	O
edit	O
operation	O
(	O
instead	O
of	O
making	O
a	O
change	O
in	O
the	O
current	O
data	B-General_Concept
structure	I-General_Concept
)	O
.	O
</s>
<s>
Many	O
common	O
data	B-General_Concept
structures	I-General_Concept
in	O
computer	O
science	O
can	O
be	O
expressed	O
as	O
the	O
structure	O
generated	O
by	O
a	O
few	O
primitive	O
constructor	O
operations	O
or	O
observer	O
operations	O
.	O
</s>
<s>
This	O
recording	O
together	O
with	O
the	O
location	O
is	O
called	O
a	O
zipped	O
representation	O
of	O
the	O
list	O
or	O
a	O
list-zipper	O
.	O
</s>
<s>
A	O
list-zipper	O
always	O
represents	O
the	O
entire	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
However	O
,	O
this	O
information	O
is	O
from	O
the	O
perspective	O
of	O
a	O
specific	O
location	O
within	O
that	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
Consequently	O
,	O
a	O
list-zipper	O
is	O
a	O
pair	O
consisting	O
of	O
both	O
the	O
location	O
as	O
a	O
context	O
or	O
starting	O
point	O
,	O
and	O
a	O
recording	O
or	O
path	O
that	O
permits	O
reconstruction	O
from	O
that	O
starting	O
location	O
.	O
</s>
<s>
In	O
particular	O
,	O
the	O
list-zipper	O
of	O
[	O
1	O
,	O
2	O
,	O
3	O
,	O
4 ]	O
at	O
the	O
location	O
of	O
"	O
3	O
"	O
may	O
be	O
represented	O
as	O
( [	O
2	O
,	O
1 ]	O
,	O
[	O
3	O
,	O
4 ]	O
)	O
.	O
</s>
<s>
Now	O
,	O
if	O
"	O
3	O
"	O
is	O
changed	O
to	O
"	O
10	O
"	O
,	O
then	O
the	O
list-zipper	O
becomes	O
( [	O
2	O
,	O
1 ]	O
,	O
[	O
10	O
,	O
4 ]	O
)	O
.	O
</s>
<s>
With	O
the	O
list	O
represented	O
this	O
way	O
,	O
it	O
is	O
easy	O
to	O
define	O
relatively	O
efficient	O
operations	O
on	O
immutable	O
data	B-General_Concept
structures	I-General_Concept
such	O
as	O
Lists	O
and	O
Trees	B-Application
at	O
arbitrary	O
locations	O
.	O
</s>
<s>
In	O
particular	O
,	O
applying	O
the	O
zipper	B-Application
transform	O
to	O
a	O
tree	O
makes	O
it	O
easy	O
to	O
insert	O
or	O
remove	O
values	O
at	O
any	O
particular	O
location	O
in	O
the	O
tree	O
.	O
</s>
<s>
The	O
type	O
of	O
a	O
zipper	B-Application
's	O
contexts	O
can	O
be	O
constructed	O
via	O
a	O
transformation	O
of	O
the	O
original	O
type	O
that	O
is	O
closely	O
related	O
to	O
the	O
derivative	B-Algorithm
of	O
calculus	O
through	O
decategorification	O
.	O
</s>
<s>
The	O
recursive	O
types	O
that	O
zippers	B-Application
are	O
formed	O
from	O
can	O
be	O
viewed	O
as	O
the	O
least	O
fixed	O
point	O
of	O
a	O
unary	O
type	O
constructor	O
of	O
kind	O
.	O
</s>
<s>
Here	O
,	O
the	O
notation	O
of	O
exponentiation	O
,	O
multiplication	O
,	O
and	O
addition	O
correspond	O
to	O
function	O
types	O
,	O
product	O
types	O
,	O
and	O
sum	B-Language
types	I-Language
respectively	O
,	O
whilst	O
the	O
natural	O
numbers	O
label	O
the	O
finite	O
types	O
;	O
in	O
this	O
way	O
,	O
the	O
type	O
constructors	O
resemble	O
polynomial	O
functions	O
in	O
.	O
</s>
<s>
The	O
derivative	B-Algorithm
of	O
a	O
type	O
constructor	O
can	O
therefore	O
be	O
formed	O
through	O
this	O
syntactic	O
analogy	O
:	O
for	O
the	O
example	O
of	O
an	O
unlabeled	O
ternary	O
tree	O
,	O
the	O
derivative	B-Algorithm
of	O
its	O
type	O
constructor	O
would	O
be	O
equivalent	O
to	O
,	O
analogously	O
to	O
the	O
use	O
of	O
the	O
sum	O
and	O
power	O
rules	O
in	O
differential	O
calculus	O
.	O
</s>
<s>
The	O
type	O
of	O
the	O
contexts	O
of	O
a	O
zipper	B-Application
over	O
an	O
original	O
type	O
is	O
equivalent	O
to	O
the	O
derivative	B-Algorithm
of	O
the	O
type	O
constructor	O
applied	O
to	O
the	O
original	O
type	O
,	O
.	O
</s>
<s>
For	O
illustration	O
,	O
consider	O
the	O
recursive	O
data	B-General_Concept
structure	I-General_Concept
of	O
a	O
binary	O
tree	O
with	O
nodes	O
that	O
are	O
either	O
sentinel	B-Data_Structure
nodes	I-Data_Structure
of	O
type	O
or	O
contain	O
a	O
value	O
of	O
type	O
:	O
</s>
<s>
a	O
boolean	O
value	O
of	O
type	O
,	O
expressing	O
whether	O
the	O
current	O
node	O
is	O
the	O
left	O
or	O
right	O
child	O
of	O
its	O
parent	B-Application
node	I-Application
;	O
</s>
<s>
the	O
node	O
's	O
sibling	O
of	O
type	O
,	O
the	O
subtree	B-Application
contained	O
by	O
the	O
other	O
branch	O
of	O
the	O
current	O
node	O
's	O
parent	O
.	O
</s>
<s>
In	O
general	O
,	O
a	O
zipper	B-Application
for	O
a	O
tree	O
of	O
type	O
consists	O
of	O
two	O
parts	O
:	O
a	O
list	O
of	O
contexts	O
of	O
type	O
of	O
the	O
current	O
node	O
and	O
each	O
of	O
its	O
ancestors	O
up	O
until	O
the	O
root	B-Application
node	I-Application
,	O
and	O
the	O
value	O
of	O
type	O
that	O
the	O
current	O
node	O
contains	O
.	O
</s>
<s>
The	O
zipper	B-Application
is	O
often	O
used	O
where	O
there	O
is	O
some	O
concept	O
of	O
focus	B-Application
or	O
of	O
moving	O
around	O
in	O
some	O
set	O
of	O
data	O
,	O
since	O
its	O
semantics	O
reflect	O
that	O
of	O
moving	O
around	O
but	O
in	O
a	O
functional	O
non-destructive	O
manner	O
.	O
</s>
<s>
A	O
filesystem	B-Application
(	O
ZipperFS	O
)	O
written	O
in	O
Haskell	B-Language
offering	O
"	O
transactional	O
...	O
semantics	O
;	O
undo	O
of	O
any	O
file	O
and	O
directory	O
operation	O
;	O
snapshots	O
;	O
statically	O
guaranteed	O
the	O
strongest	O
,	O
repeatable	O
read	O
,	O
isolation	O
mode	O
for	O
clients	O
;	O
pervasive	O
copy-on-write	O
for	O
files	O
and	O
directories	O
;	O
built-in	O
traversal	O
facility	O
;	O
and	O
just	O
the	O
right	O
behavior	O
for	O
cyclic	O
directory	O
references.	O
"	O
</s>
<s>
Clojure	B-Language
has	O
extensive	O
support	O
for	O
zippers	B-Application
.	O
</s>
<s>
In	O
a	O
non-purely-functional	O
programming	O
language	O
,	O
it	O
may	O
be	O
more	O
convenient	O
to	O
simply	O
traverse	O
the	O
original	O
data	B-General_Concept
structure	I-General_Concept
and	O
modify	O
it	O
directly	O
(	O
perhaps	O
after	O
deep	O
cloning	O
it	O
,	O
to	O
avoid	O
affecting	O
other	O
code	O
that	O
might	O
hold	O
a	O
reference	O
to	O
it	O
)	O
.	O
</s>
<s>
The	O
generic	O
zipper	B-Application
is	O
a	O
technique	O
to	O
achieve	O
the	O
same	O
goal	O
as	O
the	O
conventional	O
zipper	B-Application
by	O
capturing	O
the	O
state	O
of	O
the	O
traversal	O
in	O
a	O
continuation	O
while	O
visiting	O
each	O
node	O
.	O
</s>
<s>
(	O
The	O
Haskell	B-Language
code	O
given	O
in	O
the	O
reference	O
uses	O
generic	O
programming	O
to	O
generate	O
a	O
traversal	O
function	O
for	O
any	O
data	B-General_Concept
structure	I-General_Concept
,	O
but	O
this	O
is	O
optional	O
–	O
any	O
suitable	O
traversal	O
function	O
can	O
be	O
used	O
.	O
)	O
</s>
<s>
However	O
,	O
the	O
generic	O
zipper	B-Application
involves	O
inversion	B-Language
of	I-Language
control	I-Language
,	O
so	O
some	O
uses	O
of	O
it	O
require	O
a	O
state	B-Architecture
machine	I-Architecture
(	O
or	O
equivalent	O
)	O
to	O
keep	O
track	O
of	O
what	O
to	O
do	O
next	O
.	O
</s>
