Top Banner
Functional programming Zippers
21

Zippers presentation

Jun 27, 2015

Download

Technology

Joel Corrêa

Short presentation related to the zipper data structure
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Zippers presentation

Functional programming !Zippers!

Page 2: Zippers presentation

–Gérard Huet!

Page 3: Zippers presentation

“Zipper is a functional cursor into a data structure”

Page 4: Zippers presentation

Often used where there is some concept of 'focus' or of moving around in some set of

data.!

Page 5: Zippers presentation

Includes and generalizes the gap buffer technique

Page 6: Zippers presentation
Page 7: Zippers presentation

Data structure? Can be adapted to Lists, trees, and other recursively

defined data structures!

Page 8: Zippers presentation

Trees, Paths and Locations

Data structure!

The current element / Zipper cursor!

The current subtree / subset!

Page 9: Zippers presentation

Scalaz

Page 10: Zippers presentation

NonEmptyList!

Page 11: Zippers presentation

(2 3 5 7 11)

Sample list…

Page 12: Zippers presentation

2 (3 5 7 11)

Traversing…

Zipper!

Page 13: Zippers presentation

(2) 3 (5 7 11)

Traversing…

Zipper!

Page 14: Zippers presentation

(3 2) 5 (7 11)

Traversing.…

Zipper!

Reverse???!

Page 15: Zippers presentation

(3 2) 5 (7 11)

Traversing.…

Zipper!

Reverse???! Parent retrieve = 0(1)!

Page 16: Zippers presentation

(5 3 2) 7 (11)

Traversing..…

Zipper!

Page 17: Zippers presentation

(7 5 3 2) 11

Traversing……

Zipper!

Page 18: Zippers presentation

(11 7 5 3 2)

Traversed.

Page 19: Zippers presentation

Changes, Insertions and Deletions?

“Immutability”?!

“Laziness”?!

How to add an item?!How to delete an item?!

Page 20: Zippers presentation

Depends on the data structure, but prefer lazy evaluations

Page 21: Zippers presentation

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