Zippers presentation
Post on 27-Jun-2015
840 Views
Preview:
DESCRIPTION
Transcript
Functional programming !Zippers!
–Gérard Huet!
“Zipper is a functional cursor into a data structure”
Often used where there is some concept of 'focus' or of moving around in some set of
data.!
Includes and generalizes the gap buffer technique
Data structure? Can be adapted to Lists, trees, and other recursively
defined data structures!
Trees, Paths and Locations
Data structure!
The current element / Zipper cursor!
The current subtree / subset!
Scalaz
NonEmptyList!
(2 3 5 7 11)
Sample list…
2 (3 5 7 11)
Traversing…
Zipper!
(2) 3 (5 7 11)
Traversing…
Zipper!
(3 2) 5 (7 11)
Traversing.…
Zipper!
Reverse???!
(3 2) 5 (7 11)
Traversing.…
Zipper!
Reverse???! Parent retrieve = 0(1)!
(5 3 2) 7 (11)
Traversing..…
Zipper!
(7 5 3 2) 11
Traversing……
Zipper!
(11 7 5 3 2)
Traversed.
Changes, Insertions and Deletions?
“Immutability”?!
“Laziness”?!
How to add an item?!How to delete an item?!
Depends on the data structure, but prefer lazy evaluations
http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/TreeLoc.scala.html http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/Zipper.scala.html!
Implementation
top related