SlideShare a Scribd company logo
1 of 48
Download to read offline
How Efficient Immutable Data Enables Functional
Programming
How Efficient Immutable Data Enables Functional
Programming
or
Okasaki
For
Dummies
3 SEPTEMBER 2015
Who Am I?
4 SEPTEMBER 2015
Tom Faulhaber
➡ Planet OS CTO
➡ Background in
networking, Unix OS,
visualization, video
➡ Currently working mostly
in “Big Data”
➡ Contributor to the
Clojure programming
language
5 SEPTEMBER 2015
Who Are YOU?
6 SEPTEMBER 2015
What is functional programming?
7 SEPTEMBER 2015
8 SEPTEMBER 2015
y = f(x)
Pure Functions:
9 SEPTEMBER 2015
y = f(x)
Pure Functions:
y = f(x)
10 SEPTEMBER 2015
y = f(x)
Pure Functions:
y = f(x)y = f(x)
Not modified
Not shared
11 SEPTEMBER 2015
Higher-order Functions:
map(f, [x1, x2, ..., xn]) !
[f(x1), f(x2), ..., f(xn)]
12 SEPTEMBER 2015
Higher-order Functions:
g = map(f)
Result is a new function
13 SEPTEMBER 2015
Higher-order Functions:
g = map f
14 SEPTEMBER 2015
Other Aspects:
➡Type inference
➡Laziness
15 SEPTEMBER 2015
Functional is the opposite of
Object-oriented
16 SEPTEMBER 2015
State is
managed
through
encapsulation
Object-oriented:
State is avoided
altogether
Functional:
17 SEPTEMBER 2015
Why functional?
18 SEPTEMBER 2015
Why functional?
➡ No shared state makes it easier to reason about
programs
➡ Concurrency problems simply go away (almost!)
➡ Undo and backtracking are trivial
➡ Algorithms are often more elegant
It is better to have 100 functions operate on one data
structure than 10 functions on 10 data structures. -
Alan Perlis
19 SEPTEMBER 2015
Why functional?
A host of new languages support the functional model:
- ML, Haskell, Clojure, Scala, Idris
- All with different degrees of purity
20 SEPTEMBER 2015
There’s a catch!
21 SEPTEMBER 2015
There’s a catch!
f(5)
This is cheap:
22 SEPTEMBER 2015
There’s a catch!
f({"type": "object",
"properties": {
"mesos": {
"description": "Mesos specific configuration properties",
"type": "object",
"properties": {
"master": { … }
… } … } … } … })
But this is expensive:
23 SEPTEMBER 2015
There’s a catch!
f(<my whole database>)
And this is crazy:
24 SEPTEMBER 2015
Persistent Data Structures
to the Rescue
25 SEPTEMBER 2015
Persistent Data Structures
The goal: Approximate the performance of mutable
data structures: CPU and memory.
The big secret: Use structural sharing!
There are lots of little secrets, too. We won’t cover
them today.
26 SEPTEMBER 2015
Persistent Data Structures - History
1990 2000 2010
Persistant
Arrays
(Dietz)
ML Language
(1973)
Catenable
Queues
(Buchsbaum/
Tarjan)
Okasaki
Haskell
Language
Clojure
CollectionsFinger Trees
(1977)
Zipper
(Huet)
Data.Map
in Haskell
Priority
Search
Queues
(Hinze)
Fast And
Space Efficient
Trie Searches
(Bagwell)
Ideal Hash
Trees
(Bagwell)
RRB
Trees
(Bagwell/
Rompf)
27 SEPTEMBER 2015
The quick brown dog jumps over
6
Example: Vector
➡ In Java/C# ArrayList; in C++ std::vector.
➡ A list with constant access and update and amortized
constant append.
The quick brown fox jumps over
6 a[3] =“dog”dog
28 SEPTEMBER 2015
Example: Vector
➡ In Java/C# ArrayList; in C++ std::vector.
➡ A list with constant access and update and amortized
constant append.
The quick brown dog jumps over
6 a.push_back(“the”)
The quick brown dog jumps over
7
the
the
The quick brown dog jumps over
7
the
29 SEPTEMBER 2015
Example: Vector
➡ To build a persistent vector, we start with a tree:
Persistent
^
depth =
dlog ne
Data is in
the leaves
6
The quick brown fox jumps over
30 SEPTEMBER 2015
The quick brown fox jumps over
6
0 1 2 3 4 5
000 001 010 011 100 101
LLL LLR LRL LRR RLL RLR
The quick brown fox jumps over
6
0 1 2 3 4 5
000 001 010 011 100 101
LLL LLR LRL LRR RLL RLR
The quick brown fox jumps over
6
0 1 2 3 4 5
000 001 010 011 100 101
LLL LLR LRL LRR RLL RLR
x = a[3]
The quick brown fox jumps over
6
0 1 2 3 4 5
000 001 010 011 100 101
LLL LLR LRL LRR RLL RLR
The quick brown fox jumps over
6
0 1 2 3 4 5
000 001 010 011 100 101
LLL LLR LRL LRR RLL RLR
31 SEPTEMBER 2015
The quick brown fox jumps over
6 7
The quick brown fox jumps over
6 7
The quick brown fox jumps over
6 7
The quick brown fox jumps over
6
b = a.add(“the”)
7
The quick brown fox jumps over
6
the
32 SEPTEMBER 2015
7
The quick brown fox jumps over the
33 SEPTEMBER 2015
The quick brown fox jumps over
6
34 SEPTEMBER 2015
7
The quick brown fox jumps over
6
the
35 SEPTEMBER 2015
But, wait…
36 SEPTEMBER 2015
But, wait…
O(1) 6= O(log n)
This isn’t what you promised!
37 SEPTEMBER 2015
2
4
6
8
10
0 250 500 750 1000
Number of elements
Treedepth
2
4
6
8
10
0 250 500 750 1000
Number of elements
Treedepth
2
4
6
8
10
0 250 500 750 1000
Number of elements
Treedepth
d = 1
d = dlog2 ne
38 SEPTEMBER 2015
The answer:
Use 32-way trees
39 SEPTEMBER 2015
x = a[7022896]x = a[7022896]
00110 10110 01010 01001 10000
6 22 10 9 16
40 SEPTEMBER 2015
6
apple
22
10
9
16
41 SEPTEMBER 2015
O(1) ' O(log32 n)
42 SEPTEMBER 2015
2
4
6
8
10
0 250 500 750 1000
Number of elements
Treedepth
d = 1
d = dlog2 ne
2
4
6
8
10
0 250 500 750 1000
Number of elements
Treedepth
d = dlog32 ne
43 SEPTEMBER 2015
Example: Tree Walking
➡ The functional equivalent of the visitor pattern
44 SEPTEMBER 2015
Clojure code to implement the walker:
(postwalk
(fn [node]
(if (= :blue (:color node))
(assoc node :color :green)
node))
tree)
Example: Tree Walking
45 SEPTEMBER 2015
Example: Zippers
➡ Allow you to navigate and update a tree across many
operations by “unzipping” it.
46 SEPTEMBER 2015
Takeaways
➡ Functional data structures can approximate the
performance of mutable data structures, but will
usually won’t be quite as fast.
➡ … but not having to do state management often
wins back the difference
➡ We need to choose data structures carefully
depending on how they’re going to be used.
➡ This doesn’t solve shared state, just reduces it. (but
see message passing, software transactional
memory, etc.)
47 SEPTEMBER 2015
References
Chris Okasaki, Purely Functional Data Structures, Doctoral dissertation, Carnegie Mellon University, 1996.
Rich Hickey, “Are We There Yet?” Presentation at the JVM Languages SUmmit, 2009. http://www.infoq.com/
presentations/Are-We-There-Yet-Rich-Hickey
Gerard Huet, "Functional Pearl: The Zipper". Journal of Functional Programming 7 (5): 549–554. doi:10.1017/
s0956796897002864
Jean Niklas L’orange, “Understanding Clojure's Persistent Vectors” Blog post at http://hypirion.com/musings/
understanding-persistent-vector-pt-1.
48 SEPTEMBER 2015
Discussion

More Related Content

Viewers also liked

Faster persistent data structures through hashing
Faster persistent data structures through hashingFaster persistent data structures through hashing
Faster persistent data structures through hashingJohan Tibell
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance HaskellJohan Tibell
 
Haskell is Not For Production and Other Tales
Haskell is Not For Production and Other TalesHaskell is Not For Production and Other Tales
Haskell is Not For Production and Other TalesKatie Ots
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structureselliando dias
 
Pursuing the Strong, Not So Silent Type: A Haskell Story
Pursuing the Strong, Not So Silent Type: A Haskell StoryPursuing the Strong, Not So Silent Type: A Haskell Story
Pursuing the Strong, Not So Silent Type: A Haskell StoryKatie Ots
 
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over WebsocketIntroduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocketsametmax
 
深さ優先探索による塗りつぶし
深さ優先探索による塗りつぶし深さ優先探索による塗りつぶし
深さ優先探索による塗りつぶしAtCoder Inc.
 
Union find(素集合データ構造)
Union find(素集合データ構造)Union find(素集合データ構造)
Union find(素集合データ構造)AtCoder Inc.
 
An overview of Neo4j Internals
An overview of Neo4j InternalsAn overview of Neo4j Internals
An overview of Neo4j InternalsTobias Lindaaker
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Scott Wlaschin
 

Viewers also liked (10)

Faster persistent data structures through hashing
Faster persistent data structures through hashingFaster persistent data structures through hashing
Faster persistent data structures through hashing
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
Haskell is Not For Production and Other Tales
Haskell is Not For Production and Other TalesHaskell is Not For Production and Other Tales
Haskell is Not For Production and Other Tales
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Pursuing the Strong, Not So Silent Type: A Haskell Story
Pursuing the Strong, Not So Silent Type: A Haskell StoryPursuing the Strong, Not So Silent Type: A Haskell Story
Pursuing the Strong, Not So Silent Type: A Haskell Story
 
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over WebsocketIntroduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
 
深さ優先探索による塗りつぶし
深さ優先探索による塗りつぶし深さ優先探索による塗りつぶし
深さ優先探索による塗りつぶし
 
Union find(素集合データ構造)
Union find(素集合データ構造)Union find(素集合データ構造)
Union find(素集合データ構造)
 
An overview of Neo4j Internals
An overview of Neo4j InternalsAn overview of Neo4j Internals
An overview of Neo4j Internals
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 

Similar to Efficient Immutable Data Structures (Okasaki for Dummies)

Data Structures for Statistical Computing in Python
Data Structures for Statistical Computing in PythonData Structures for Statistical Computing in Python
Data Structures for Statistical Computing in PythonWes McKinney
 
Mikio Braun – Data flow vs. procedural programming
Mikio Braun – Data flow vs. procedural programming Mikio Braun – Data flow vs. procedural programming
Mikio Braun – Data flow vs. procedural programming Flink Forward
 
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...Sebastian Wild
 
The State of OW2. OW2con'15, November 17, Paris.
The State of OW2. OW2con'15, November 17, Paris. The State of OW2. OW2con'15, November 17, Paris.
The State of OW2. OW2con'15, November 17, Paris. OW2
 
Nix for etl using scripting to automate data cleaning & transformation
Nix for etl using scripting to automate data cleaning & transformationNix for etl using scripting to automate data cleaning & transformation
Nix for etl using scripting to automate data cleaning & transformationLynchpin Analytics Consultancy
 
Observe Changes of Taiwan Big Data Communities with Small Data
Observe Changes of Taiwan Big Data Communities with Small DataObserve Changes of Taiwan Big Data Communities with Small Data
Observe Changes of Taiwan Big Data Communities with Small DataJazz Yao-Tsung Wang
 
Puppet Camp Tokyo 2014: Fireballs, ice bats and 1,000,000 plugins: a story of...
Puppet Camp Tokyo 2014: Fireballs, ice bats and 1,000,000 plugins: a story of...Puppet Camp Tokyo 2014: Fireballs, ice bats and 1,000,000 plugins: a story of...
Puppet Camp Tokyo 2014: Fireballs, ice bats and 1,000,000 plugins: a story of...Puppet
 
Skutil - H2O meets Sklearn - Taylor Smith
Skutil - H2O meets Sklearn - Taylor SmithSkutil - H2O meets Sklearn - Taylor Smith
Skutil - H2O meets Sklearn - Taylor SmithSri Ambati
 
WISS 2015 - Machine Learning lecture by Ludovic Samper
WISS 2015 - Machine Learning lecture by Ludovic Samper WISS 2015 - Machine Learning lecture by Ludovic Samper
WISS 2015 - Machine Learning lecture by Ludovic Samper Antidot
 
Antlr4 get the right tool for the job
Antlr4   get the right tool for the jobAntlr4   get the right tool for the job
Antlr4 get the right tool for the jobAlexander Pacha
 
Visual-Textual Joint Relevance Learning for Tag-Based Social Image Search
Visual-Textual Joint Relevance Learning for Tag-Based Social Image SearchVisual-Textual Joint Relevance Learning for Tag-Based Social Image Search
Visual-Textual Joint Relevance Learning for Tag-Based Social Image SearchBABU MALVIYA
 
The Rise of the DataOps - Dataiku - J On the Beach 2016
The Rise of the DataOps - Dataiku - J On the Beach 2016 The Rise of the DataOps - Dataiku - J On the Beach 2016
The Rise of the DataOps - Dataiku - J On the Beach 2016 Dataiku
 
Introduction to Oracle R for Big Data Analysis
Introduction to Oracle R for Big Data AnalysisIntroduction to Oracle R for Big Data Analysis
Introduction to Oracle R for Big Data AnalysisRevelation Technologies
 
introtorandrstudio.ppt
introtorandrstudio.pptintrotorandrstudio.ppt
introtorandrstudio.pptMalkaParveen3
 
SIGSPL.org | Labour, Arts and Analysis united
SIGSPL.org | Labour, Arts and Analysis unitedSIGSPL.org | Labour, Arts and Analysis united
SIGSPL.org | Labour, Arts and Analysis unitedSIGSPL.org
 
Den moderne dataplatform - gør din dataplatform til det mest værdifulde asset
Den moderne dataplatform - gør din dataplatform til det mest værdifulde asset Den moderne dataplatform - gør din dataplatform til det mest værdifulde asset
Den moderne dataplatform - gør din dataplatform til det mest værdifulde asset Microsoft
 
Idescat on the Google Public Data Explorer
Idescat on the Google Public Data ExplorerIdescat on the Google Public Data Explorer
Idescat on the Google Public Data ExplorerXavier Badosa
 
Customer Segmentation with R - Deep Dive into flexclust
Customer Segmentation with R - Deep Dive into flexclustCustomer Segmentation with R - Deep Dive into flexclust
Customer Segmentation with R - Deep Dive into flexclustJim Porzak
 

Similar to Efficient Immutable Data Structures (Okasaki for Dummies) (20)

Data Structures for Statistical Computing in Python
Data Structures for Statistical Computing in PythonData Structures for Statistical Computing in Python
Data Structures for Statistical Computing in Python
 
Mikio Braun – Data flow vs. procedural programming
Mikio Braun – Data flow vs. procedural programming Mikio Braun – Data flow vs. procedural programming
Mikio Braun – Data flow vs. procedural programming
 
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
Dual-Pivot Quicksort and Beyond: Analysis of Multiway Partitioning and Its Pr...
 
The State of OW2. OW2con'15, November 17, Paris.
The State of OW2. OW2con'15, November 17, Paris. The State of OW2. OW2con'15, November 17, Paris.
The State of OW2. OW2con'15, November 17, Paris.
 
Nix for etl using scripting to automate data cleaning & transformation
Nix for etl using scripting to automate data cleaning & transformationNix for etl using scripting to automate data cleaning & transformation
Nix for etl using scripting to automate data cleaning & transformation
 
Observe Changes of Taiwan Big Data Communities with Small Data
Observe Changes of Taiwan Big Data Communities with Small DataObserve Changes of Taiwan Big Data Communities with Small Data
Observe Changes of Taiwan Big Data Communities with Small Data
 
Puppet Camp Tokyo 2014: Fireballs, ice bats and 1,000,000 plugins: a story of...
Puppet Camp Tokyo 2014: Fireballs, ice bats and 1,000,000 plugins: a story of...Puppet Camp Tokyo 2014: Fireballs, ice bats and 1,000,000 plugins: a story of...
Puppet Camp Tokyo 2014: Fireballs, ice bats and 1,000,000 plugins: a story of...
 
Skutil - H2O meets Sklearn - Taylor Smith
Skutil - H2O meets Sklearn - Taylor SmithSkutil - H2O meets Sklearn - Taylor Smith
Skutil - H2O meets Sklearn - Taylor Smith
 
WISS 2015 - Machine Learning lecture by Ludovic Samper
WISS 2015 - Machine Learning lecture by Ludovic Samper WISS 2015 - Machine Learning lecture by Ludovic Samper
WISS 2015 - Machine Learning lecture by Ludovic Samper
 
Antlr4 get the right tool for the job
Antlr4   get the right tool for the jobAntlr4   get the right tool for the job
Antlr4 get the right tool for the job
 
python.ppt
python.pptpython.ppt
python.ppt
 
Visual-Textual Joint Relevance Learning for Tag-Based Social Image Search
Visual-Textual Joint Relevance Learning for Tag-Based Social Image SearchVisual-Textual Joint Relevance Learning for Tag-Based Social Image Search
Visual-Textual Joint Relevance Learning for Tag-Based Social Image Search
 
The Rise of the DataOps - Dataiku - J On the Beach 2016
The Rise of the DataOps - Dataiku - J On the Beach 2016 The Rise of the DataOps - Dataiku - J On the Beach 2016
The Rise of the DataOps - Dataiku - J On the Beach 2016
 
Introduction to Oracle R for Big Data Analysis
Introduction to Oracle R for Big Data AnalysisIntroduction to Oracle R for Big Data Analysis
Introduction to Oracle R for Big Data Analysis
 
introtorandrstudio.ppt
introtorandrstudio.pptintrotorandrstudio.ppt
introtorandrstudio.ppt
 
SIGSPL.org | Labour, Arts and Analysis united
SIGSPL.org | Labour, Arts and Analysis unitedSIGSPL.org | Labour, Arts and Analysis united
SIGSPL.org | Labour, Arts and Analysis united
 
Den moderne dataplatform - gør din dataplatform til det mest værdifulde asset
Den moderne dataplatform - gør din dataplatform til det mest værdifulde asset Den moderne dataplatform - gør din dataplatform til det mest værdifulde asset
Den moderne dataplatform - gør din dataplatform til det mest værdifulde asset
 
Idescat on the Google Public Data Explorer
Idescat on the Google Public Data ExplorerIdescat on the Google Public Data Explorer
Idescat on the Google Public Data Explorer
 
Practical Magic with Incanter
Practical Magic with IncanterPractical Magic with Incanter
Practical Magic with Incanter
 
Customer Segmentation with R - Deep Dive into flexclust
Customer Segmentation with R - Deep Dive into flexclustCustomer Segmentation with R - Deep Dive into flexclust
Customer Segmentation with R - Deep Dive into flexclust
 

Recently uploaded

Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 

Recently uploaded (20)

Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 

Efficient Immutable Data Structures (Okasaki for Dummies)

  • 1. How Efficient Immutable Data Enables Functional Programming
  • 2. How Efficient Immutable Data Enables Functional Programming or Okasaki For Dummies
  • 4. 4 SEPTEMBER 2015 Tom Faulhaber ➡ Planet OS CTO ➡ Background in networking, Unix OS, visualization, video ➡ Currently working mostly in “Big Data” ➡ Contributor to the Clojure programming language
  • 6. 6 SEPTEMBER 2015 What is functional programming?
  • 8. 8 SEPTEMBER 2015 y = f(x) Pure Functions:
  • 9. 9 SEPTEMBER 2015 y = f(x) Pure Functions: y = f(x)
  • 10. 10 SEPTEMBER 2015 y = f(x) Pure Functions: y = f(x)y = f(x) Not modified Not shared
  • 11. 11 SEPTEMBER 2015 Higher-order Functions: map(f, [x1, x2, ..., xn]) ! [f(x1), f(x2), ..., f(xn)]
  • 12. 12 SEPTEMBER 2015 Higher-order Functions: g = map(f) Result is a new function
  • 13. 13 SEPTEMBER 2015 Higher-order Functions: g = map f
  • 14. 14 SEPTEMBER 2015 Other Aspects: ➡Type inference ➡Laziness
  • 15. 15 SEPTEMBER 2015 Functional is the opposite of Object-oriented
  • 16. 16 SEPTEMBER 2015 State is managed through encapsulation Object-oriented: State is avoided altogether Functional:
  • 17. 17 SEPTEMBER 2015 Why functional?
  • 18. 18 SEPTEMBER 2015 Why functional? ➡ No shared state makes it easier to reason about programs ➡ Concurrency problems simply go away (almost!) ➡ Undo and backtracking are trivial ➡ Algorithms are often more elegant It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures. - Alan Perlis
  • 19. 19 SEPTEMBER 2015 Why functional? A host of new languages support the functional model: - ML, Haskell, Clojure, Scala, Idris - All with different degrees of purity
  • 21. 21 SEPTEMBER 2015 There’s a catch! f(5) This is cheap:
  • 22. 22 SEPTEMBER 2015 There’s a catch! f({"type": "object", "properties": { "mesos": { "description": "Mesos specific configuration properties", "type": "object", "properties": { "master": { … } … } … } … } … }) But this is expensive:
  • 23. 23 SEPTEMBER 2015 There’s a catch! f(<my whole database>) And this is crazy:
  • 24. 24 SEPTEMBER 2015 Persistent Data Structures to the Rescue
  • 25. 25 SEPTEMBER 2015 Persistent Data Structures The goal: Approximate the performance of mutable data structures: CPU and memory. The big secret: Use structural sharing! There are lots of little secrets, too. We won’t cover them today.
  • 26. 26 SEPTEMBER 2015 Persistent Data Structures - History 1990 2000 2010 Persistant Arrays (Dietz) ML Language (1973) Catenable Queues (Buchsbaum/ Tarjan) Okasaki Haskell Language Clojure CollectionsFinger Trees (1977) Zipper (Huet) Data.Map in Haskell Priority Search Queues (Hinze) Fast And Space Efficient Trie Searches (Bagwell) Ideal Hash Trees (Bagwell) RRB Trees (Bagwell/ Rompf)
  • 27. 27 SEPTEMBER 2015 The quick brown dog jumps over 6 Example: Vector ➡ In Java/C# ArrayList; in C++ std::vector. ➡ A list with constant access and update and amortized constant append. The quick brown fox jumps over 6 a[3] =“dog”dog
  • 28. 28 SEPTEMBER 2015 Example: Vector ➡ In Java/C# ArrayList; in C++ std::vector. ➡ A list with constant access and update and amortized constant append. The quick brown dog jumps over 6 a.push_back(“the”) The quick brown dog jumps over 7 the the The quick brown dog jumps over 7 the
  • 29. 29 SEPTEMBER 2015 Example: Vector ➡ To build a persistent vector, we start with a tree: Persistent ^ depth = dlog ne Data is in the leaves 6 The quick brown fox jumps over
  • 30. 30 SEPTEMBER 2015 The quick brown fox jumps over 6 0 1 2 3 4 5 000 001 010 011 100 101 LLL LLR LRL LRR RLL RLR The quick brown fox jumps over 6 0 1 2 3 4 5 000 001 010 011 100 101 LLL LLR LRL LRR RLL RLR The quick brown fox jumps over 6 0 1 2 3 4 5 000 001 010 011 100 101 LLL LLR LRL LRR RLL RLR x = a[3] The quick brown fox jumps over 6 0 1 2 3 4 5 000 001 010 011 100 101 LLL LLR LRL LRR RLL RLR The quick brown fox jumps over 6 0 1 2 3 4 5 000 001 010 011 100 101 LLL LLR LRL LRR RLL RLR
  • 31. 31 SEPTEMBER 2015 The quick brown fox jumps over 6 7 The quick brown fox jumps over 6 7 The quick brown fox jumps over 6 7 The quick brown fox jumps over 6 b = a.add(“the”) 7 The quick brown fox jumps over 6 the
  • 32. 32 SEPTEMBER 2015 7 The quick brown fox jumps over the
  • 33. 33 SEPTEMBER 2015 The quick brown fox jumps over 6
  • 34. 34 SEPTEMBER 2015 7 The quick brown fox jumps over 6 the
  • 36. 36 SEPTEMBER 2015 But, wait… O(1) 6= O(log n) This isn’t what you promised!
  • 37. 37 SEPTEMBER 2015 2 4 6 8 10 0 250 500 750 1000 Number of elements Treedepth 2 4 6 8 10 0 250 500 750 1000 Number of elements Treedepth 2 4 6 8 10 0 250 500 750 1000 Number of elements Treedepth d = 1 d = dlog2 ne
  • 38. 38 SEPTEMBER 2015 The answer: Use 32-way trees
  • 39. 39 SEPTEMBER 2015 x = a[7022896]x = a[7022896] 00110 10110 01010 01001 10000 6 22 10 9 16
  • 41. 41 SEPTEMBER 2015 O(1) ' O(log32 n)
  • 42. 42 SEPTEMBER 2015 2 4 6 8 10 0 250 500 750 1000 Number of elements Treedepth d = 1 d = dlog2 ne 2 4 6 8 10 0 250 500 750 1000 Number of elements Treedepth d = dlog32 ne
  • 43. 43 SEPTEMBER 2015 Example: Tree Walking ➡ The functional equivalent of the visitor pattern
  • 44. 44 SEPTEMBER 2015 Clojure code to implement the walker: (postwalk (fn [node] (if (= :blue (:color node)) (assoc node :color :green) node)) tree) Example: Tree Walking
  • 45. 45 SEPTEMBER 2015 Example: Zippers ➡ Allow you to navigate and update a tree across many operations by “unzipping” it.
  • 46. 46 SEPTEMBER 2015 Takeaways ➡ Functional data structures can approximate the performance of mutable data structures, but will usually won’t be quite as fast. ➡ … but not having to do state management often wins back the difference ➡ We need to choose data structures carefully depending on how they’re going to be used. ➡ This doesn’t solve shared state, just reduces it. (but see message passing, software transactional memory, etc.)
  • 47. 47 SEPTEMBER 2015 References Chris Okasaki, Purely Functional Data Structures, Doctoral dissertation, Carnegie Mellon University, 1996. Rich Hickey, “Are We There Yet?” Presentation at the JVM Languages SUmmit, 2009. http://www.infoq.com/ presentations/Are-We-There-Yet-Rich-Hickey Gerard Huet, "Functional Pearl: The Zipper". Journal of Functional Programming 7 (5): 549–554. doi:10.1017/ s0956796897002864 Jean Niklas L’orange, “Understanding Clojure's Persistent Vectors” Blog post at http://hypirion.com/musings/ understanding-persistent-vector-pt-1.