Fate and functional programming
Upcoming SlideShare
Loading in...5
×
 

Fate and functional programming

on

  • 287 views

Introduction to functional programming concepts and their application to data. Discuss pros/cons of a functional style. Discuss relationship between functional programming and the nature of the ...

Introduction to functional programming concepts and their application to data. Discuss pros/cons of a functional style. Discuss relationship between functional programming and the nature of the universe.

Statistics

Views

Total Views
287
Slideshare-icon Views on SlideShare
283
Embed Views
4

Actions

Likes
1
Downloads
2
Comments
0

1 Embed 4

http://www.linkedin.com 4

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Fate and functional programming Fate and functional programming Presentation Transcript

    • Fate Free will Functional πrogramming Rino Jose Thursday, October 31, 13 1
    • Definitions Thursday, October 31, 13 2
    • Definitions Set: Collection of unique elements Thursday, October 31, 13 2
    • Definitions Set: Collection of unique elements Function: Rule that associates elements in one set with those in another α β γ π Thursday, October 31, 13 2
    • Function: digitOfPi Thursday, October 31, 13 3
    • Function: digitOfPi digitOfPi :: Int -> Digit Thursday, October 31, 13 3
    • Function: digitOfPi digitOfPi :: Int -> Digit 1 2 3 4 ∶ Thursday, October 31, 13 0 1 2 3 4 5 6 7 8 9 3
    • Function: digitOfPi digitOfPi :: Int -> Digit 1 2 3 4 ∶ Thursday, October 31, 13 0 1 2 3 4 5 6 7 8 9 3
    • Algorithm is Irrelevant Thursday, October 31, 13 4
    • Algorithm is Irrelevant • Only the association/mapping matters • Thursday, October 31, 13 May need an algorithm to find the mapping 4
    • Algorithm is Irrelevant • Only the association/mapping matters • • Once mapping is known, it can be used in place of the algo without changing any behavior • • Thursday, October 31, 13 May need an algorithm to find the mapping This is “referential transparency” Implies no side effects when algorithm is run 4
    • Algorithm is Irrelevant • Only the association/mapping matters • • Once mapping is known, it can be used in place of the algo without changing any behavior • • • This is “referential transparency” Implies no side effects when algorithm is run Example: digits of π • • Thursday, October 31, 13 May need an algorithm to find the mapping Algorithms exist for computing digits of π But digits are predetermined by how π is defined 4
    • π? Thursday, October 31, 13 5
    • π? Thursday, October 31, 13 5
    • π? Thursday, October 31, 13 5
    • π? π= Thursday, October 31, 13 circumference diameter 5
    • Algo is Irrelevant • Only the association/mapping matters • • But once mapping is known, it can be used in place of the algo without changing any behavior • • • This is “referential transparency” Implies no side effects from algos used Example: digits of π • • Thursday, October 31, 13 May need an algorithm to find the mapping Algorithms exist for computing digits of π However, digits of π exist by definition of π 6
    • Algo is Irrelevant • Only the association/mapping matters • • But once mapping is known, it can be used in place of the algo without changing any behavior • • • This is “referential transparency” Implies no side effects from algos used Example: digits of π • • Thursday, October 31, 13 May need an algorithm to find the mapping Algorithms exist for computing digits of π However, digits of π exist by definition of π 6
    • Multiple Arguments? Thursday, October 31, 13 7
    • Multiple Arguments? sliceOfPi start num -> Int sliceOfPi 2 3 = 141 Thursday, October 31, 13 7
    • Multiple Arguments? sliceOfPi start num -> Int sliceOfPi 2 3 = 141 1 2 3 ∶ 1 2 ∶ 141 ∶ start Thursday, October 31, 13 1 2 3 ∶ num Int 7
    • Multiple Arguments? sliceOfPi start num -> Int sliceOfPi 2 3 = 141 sliceOfPi 2 3 = firstNDigitsOfPiStartingAtDigit2 3 = 141 sliceOfPi 2 3 = f2 3 = 141 1 2 3 ∶ start Thursday, October 31, 13 f1 f2 f3 1 2 3 ∶ 1 2 ∶ 141 ∶ num Int 7
    • Multiple Arguments? What if we called sliceOfPi with only one argument? 1 2 3 ∶ Thursday, October 31, 13 f1 f2 f3 8
    • Multiple Arguments? What if we called sliceOfPi with only one argument? sliceOfPi 2 = f2 1 2 3 ∶ Thursday, October 31, 13 f1 f2 f3 8
    • Multiple Arguments? What if we called sliceOfPi with only one argument? sliceOfPi 2 = f2 Partial function application 1 2 3 ∶ Thursday, October 31, 13 f1 f2 f3 8
    • Multiple Arguments? What if we called sliceOfPi with only one argument? sliceOfPi 2 = f2 Partial function application a.k.a. currying after Haskell Curry 1 2 3 ∶ Thursday, October 31, 13 f1 f2 f3 8
    • Multiple Arguments? This looks very similar to a unix pipeline 1 2 3 ∶ Thursday, October 31, 13 f1 f2 f3 1 2 3 ∶ 1 2 ∶ 141 ∶ 9
    • Multiple Arguments? This looks very similar to a unix pipeline 1 2 3 ∶ Thursday, October 31, 13 stdin f1 f2 f3 args 1 2 3 ∶ stdout 1 2 ∶ 141 ∶ 9
    • Pipelines are Functional Thursday, October 31, 13 10
    • Pipelines are Functional Each step in a Unix pipeline is a function call: ls . | grep r | grep i | grep n | grep o | wc -l Thursday, October 31, 13 10
    • Pipelines are Functional Each step in a Unix pipeline is a function call: ls . | grep r | grep i | grep n | grep o | wc -l ls :: Dir -> String grep :: String -> String -> String wc :: String -> String Thursday, October 31, 13 10
    • Pipelines are Functional Each step in a Unix pipeline is a function call: ls . | grep r | grep i | grep n | grep o | wc -l ls :: Dir -> String grep :: String -> String -> String wc :: String -> String Pipelines are referentially transparent: ls | grep r | grep i > value.txt cat value.txt | grep n | grep o | wc -l Thursday, October 31, 13 10
    • ETL is a pipeline Thursday, October 31, 13 11
    • ETL is a pipeline Extract | Transform | Load Thursday, October 31, 13 11
    • ETL is a pipeline Extract | Transform | Load E Thursday, October 31, 13 T L 11
    • ETL is a pipeline Extract | Transform | Load E T L Why not just Extract and Load? Thursday, October 31, 13 11
    • ETL is a pipeline Extract | Transform | Load E T L Why not just Extract and Load? The transform step makes data more regular, reducing the nondeterminism in the input data sources. Thursday, October 31, 13 11
    • Nondeterminism Thursday, October 31, 13 12
    • Nondeterminism Nondeterminism: randomness in input and output Thursday, October 31, 13 12
    • Nondeterminism Nondeterminism: randomness in input and output digitOfPi :: Int -> Digit Thursday, October 31, 13 No uncertainty 12
    • Nondeterminism Nondeterminism: randomness in input and output digitOfPi :: Int -> Digit n ∈ {1, 2, 4} Thursday, October 31, 13 No uncertainty Input uncertainty 12
    • Nondeterminism Nondeterminism: randomness in input and output digitOfPi :: Int -> Digit n ∈ {1, 2, 4} digitOfPi n ∈ {1, 3} Thursday, October 31, 13 No uncertainty Input uncertainty Output uncertainty 12
    • Nondeterminism Nondeterminism: randomness in input and output digitOfPi :: Int -> Digit No uncertainty n ∈ {1, 2, 4} digitOfPi n ∈ {1, 3} Input uncertainty Output uncertainty What is the result? 1 or 3? Thursday, October 31, 13 12
    • Nondeterminism Nondeterminism: randomness in input and output digitOfPi :: Int -> Digit No uncertainty n ∈ {1, 2, 4} digitOfPi n ∈ {1, 3} Input uncertainty Output uncertainty What is the result? 1 or 3? Domain of s uantum computer q Thursday, October 31, 13 12
    • Deepank’s Roulette Thursday, October 31, 13 13
    • Deepank’s Roulette • Thursday, October 31, 13 Deepank is in a room with a roulette wheel 13
    • Deepank’s Roulette • • Thursday, October 31, 13 Deepank is in a room with a roulette wheel Bets on red 13
    • Deepank’s Roulette • • • Thursday, October 31, 13 Deepank is in a room with a roulette wheel Bets on red Spins wheel 13
    • Deepank’s Roulette • • • Deepank is in a room with a roulette wheel Bets on red Spins wheel • Thursday, October 31, 13 If lands on red, 13
    • Deepank’s Roulette • • • Deepank is in a room with a roulette wheel Bets on red Spins wheel • Thursday, October 31, 13 If lands on red, he takes his winnings home 13
    • Deepank’s Roulette • • • Deepank is in a room with a roulette wheel Bets on red Spins wheel • • Thursday, October 31, 13 If lands on red, he takes his winnings home If lands on black, 13
    • Deepank’s Roulette • • • Deepank is in a room with a roulette wheel Bets on red Spins wheel • • Thursday, October 31, 13 If lands on red, he takes his winnings home If lands on black, he dies 13
    • Deepank’s Roulette • • • Deepank is in a room with a roulette wheel Bets on red Spins wheel • • • Thursday, October 31, 13 If lands on red, he takes his winnings home If lands on black, he dies Close door and spin wheel 13
    • Deepank’s Roulette • • • Deepank is in a room with a roulette wheel Bets on red Spins wheel • • If lands on red, he takes his winnings home If lands on black, he dies • • Thursday, October 31, 13 Close door and spin wheel Is Deepank richer or dead? 13
    • Deepank’s Roulette • • • Deepank is in a room with a roulette wheel Bets on red Spins wheel • • • If lands on red, he takes his winnings home If lands on black, he dies Close door and spin wheel $$ • Thursday, October 31, 13 Is Deepank richer or dead? 13
    • Deepank’s Roulette • • • Deepank is in a room with a roulette wheel Bets on red Spins wheel • • • If lands on red, he takes his winnings home If lands on black, he dies Close door and spin wheel • Thursday, October 31, 13 xx ( $$ Is Deepank richer or dead? 13
    • Deepank’s Roulette • • • Deepank is in a room with a roulette wheel Bets on red Spins wheel • • • If lands on red, he takes his winnings home If lands on black, he dies Close door and spin wheel • Is Deepank richer or dead? • Thursday, October 31, 13 xx ( $$ Both − depends on the universe 13
    • Multiple Universes Thursday, October 31, 13 14
    • Multiple Universes In any given universe, everything that has ever happened or ever will happen exists independently and unchangeable. Thursday, October 31, 13 14
    • Multiple Universes In any given universe, everything that has ever happened or ever will happen exists independently and unchangeable. Just like the digits of pi 3.141592653589793238462643383279502884197169399375 10582097494459230781640628620899862803482534211706 79821480865132823066470938446095505822317253594081 28481117450284102701938521105559644622948954930381 96442881097566593344612847564823378678316527120190 91456485669234603486104543266482133936072602491412 73724587006606315588174881520920962829254091715364 36789259036001133053054882046652138414695194151160 94330572703657595919530921861173819326117931051185 Thursday, October 31, 13 14
    • Fate and π Thursday, October 31, 13 15
    • Fate and π Conjecture: π contains all finite sequences of digits. Thursday, October 31, 13 15
    • Fate and π Conjecture: π contains all finite sequences of digits. Profound if true Thursday, October 31, 13 15
    • Fate and π Conjecture: π contains all finite sequences of digits. Profound if true π contains... Thursday, October 31, 13 15
    • Fate and π Conjecture: π contains all finite sequences of digits. Profound if true π contains... • ...a transcript of everything you will ever say Thursday, October 31, 13 15
    • Fate and π Conjecture: π contains all finite sequences of digits. Profound if true π contains... • ...a transcript of everything you will ever say • ...a tarball of next week’s mobile source code Thursday, October 31, 13 15
    • Fate and π Conjecture: π contains all finite sequences of digits. Profound if true π contains... • ...a transcript of everything you will ever say • ...a tarball of next week’s mobile source code • ...a video of you with thought bubbles...in Spanish Thursday, October 31, 13 15
    • Fate and π Conjecture: π contains all finite sequences of digits. Profound if true π contains... • ...a transcript of everything you will ever say • ...a tarball of next week’s mobile source code • ...a video of you with thought bubbles...in Spanish • ...all human knowledge and all variations of it Thursday, October 31, 13 15
    • Fate and π Conjecture: π contains all finite sequences of digits. Profound if true π contains... • ...a transcript of everything you will ever say • ...a tarball of next week’s mobile source code • ...a video of you with thought bubbles...in Spanish • ...all human knowledge and all variations of it If true, our existence is probably part of an algorithm to compute the digits of π. Thursday, October 31, 13 15
    • Fate and π Conjecture: π contains all finite sequences of digits. Profound if true π contains... • ...a transcript of everything you will ever say • ...a tarball of next week’s mobile source code • ...a video of you with thought bubbles...in Spanish • ...all human knowledge and all variations of it If true, our existence is probably part of an algorithm to compute the digits of π. Thursday, October 31, 13 15
    • Free Will Thursday, October 31, 13 16
    • Free Will Thursday, October 31, 13 $$ xx ( Multiverse Theory There is a universe associated with every combination of nondeterminism. 16
    • Free Will $$ xx ( Multiverse Theory There is a universe associated with every combination of nondeterminism. Terminator principle There is no fate but what we make. Thursday, October 31, 13 16
    • Free Will $$ xx ( Multiverse Theory There is a universe associated with every combination of nondeterminism. Terminator principle There is no fate but what we make. Make good choices We select our universe by making choices. Thursday, October 31, 13 16
    • Free Will $$ xx ( Multiverse Theory There is a universe associated with every combination of nondeterminism. Terminator principle There is no fate but what we make. Make good choices We select our universe by making choices. This may also xplain jinxes e Thursday, October 31, 13 16
    • Nondeterminism Nondeterminism: randomness in input and output digitOfPi :: Int -> Digit No uncertainty n ∈ {1, 2, 4} digitOfPi n ∈ {1, 3} Input uncertainty Output uncertainty What is the result? 1 or 3? se case for U computers quantum Thursday, October 31, 13 17
    • Nondeterminism in SW Thursday, October 31, 13 18
    • Nondeterminism in SW Nondeterminism makes testing and debugging harder Thursday, October 31, 13 18
    • Nondeterminism in SW Nondeterminism makes testing and debugging harder • More scenarios to set up • More cases to check • More universes to consider Thursday, October 31, 13 18
    • Nondeterminism in SW Nondeterminism makes testing and debugging harder • More scenarios to set up • More cases to check • More universes to consider Sources of nondeterminism Thursday, October 31, 13 18
    • Nondeterminism in SW Nondeterminism makes testing and debugging harder • More scenarios to set up • More cases to check • More universes to consider Sources of nondeterminism • Side effects • Un-DRY code • Breaking “Law of Demeter” • Irregular return values Thursday, October 31, 13 18
    • Nondeterminism in SW Nondeterminism makes testing and debugging harder • More scenarios to set up • More cases to check • More universes to consider Sources of nondeterminism • Side effects • Un-DRY code • Breaking “Law of Demeter” • Irregular return values Ask Yourself Is this function increasing or reducing nondeterminism? Thursday, October 31, 13 18
    • Reduce Nondeterminism Thursday, October 31, 13 19
    • Reduce Nondeterminism •Use ETL as a model Thursday, October 31, 13 19
    • Reduce Nondeterminism •Use ETL as a model •Make functions referentially transparent Thursday, October 31, 13 19
    • Reduce Nondeterminism •Use ETL as a model •Make functions referentially transparent •Isolate code that changes state Thursday, October 31, 13 19
    • Reduce Nondeterminism •Use ETL as a model •Make functions referentially transparent •Isolate code that changes state •Ensure function results are regular • Use placeholders so callers won’t need to check • Keep the result set as unvaried as possible • Unleash your unit tests here Thursday, October 31, 13 19
    • Reduce Nondeterminism •Use ETL as a model •Make functions referentially transparent •Isolate code that changes state •Ensure function results are regular • Use placeholders so callers won’t need to check • Keep the result set as unvaried as possible • Unleash your unit tests here Reducing nondeterminism lets you make stronger assumptions about the code. Thursday, October 31, 13 19
    • Databending Thursday, October 31, 13 20
    • Databending Thursday, October 31, 13 20
    • Databending Extract Raw Data Thursday, October 31, 13 20
    • Databending Extract Raw Data Condition Data Thursday, October 31, 13 20
    • Databending Bend Data Extract Raw Data Condition Data Thursday, October 31, 13 20
    • Databending Load Data Bend Data Extract Raw Data Condition Data Thursday, October 31, 13 20
    • Databending Load Data Bend Data Extract Raw Data Condition Data Snapshot Service • Data is snapshotted Thursday, October 31, 13 20
    • Databending Load Data Bend Data Extract Raw Data Condition Data Snapshot Service • Data is snapshotted • Stages provide robustness Thursday, October 31, 13 20
    • Databending Load Data Bend Data Extract Raw Data Condition Data Snapshot Service • Data is snapshotted • Stages provide robustness • Nondeterminism decreases Thursday, October 31, 13 20
    • Takeaway Thoughts Thursday, October 31, 13 21
    • Takeaway Thoughts • Thursday, October 31, 13 Use functional ideas to reduce nondeterminism 21
    • Takeaway Thoughts • • Thursday, October 31, 13 Use functional ideas to reduce nondeterminism Make good choices to select good universes 21
    • Takeaway Thoughts • • Make good choices to select good universes • Thursday, October 31, 13 Use functional ideas to reduce nondeterminism Don’t play roulette with Deepank 21
    • Thursday, October 31, 13 22
    • uestions? Thursday, October 31, 13 22