Commercial Uses of Functional Programming

140
2014-07-01 FLOLAC’14 C ommercial U ses of F unctional P rogramming Functional Programming as a means — not an end

description

FLOLAC'14 talk on using Haskell in commercial settings.

Transcript of Commercial Uses of Functional Programming

Page 1: Commercial Uses of Functional Programming

2014-07-01 FLOLAC’14

Commercial Uses of Functional ProgrammingFunctional Programming as a means — not an end

Page 2: Commercial Uses of Functional Programming

01

Page 3: Commercial Uses of Functional Programming

01

✤ ICFP 2014: September 1~3

Page 4: Commercial Uses of Functional Programming

01

✤ ICFP 2014: September 1~3

✤ CUFP 2014: September 4~6

Page 5: Commercial Uses of Functional Programming

01

✤ ICFP 2014: September 1~3

✤ CUFP 2014: September 4~6

✤ 6-Hour Workday: July 1

Page 12: Commercial Uses of Functional Programming

Less is more!

λClosure ⊂ Value

Page 13: Commercial Uses of Functional Programming

Less is more!

λClosure ⊂ Value f . g =

Page 14: Commercial Uses of Functional Programming

Less is more!

λClosure ⊂ Value f . g = \x -> f (g x)

Page 15: Commercial Uses of Functional Programming

Less is more!

λClosure ⊂ Value f . g = \x -> f (g x)

((+1) . (*2)) 3

Page 16: Commercial Uses of Functional Programming

Less is more!

λClosure ⊂ Value

function compose (f, g) { return function (x) { return f( g(x) ) } }

f . g = \x -> f (g x)

((+1) . (*2)) 3

Page 17: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 18: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 19: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 20: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 21: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 22: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 23: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 24: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 25: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 26: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 27: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 28: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 29: Commercial Uses of Functional Programming

ANSI C AdaFortran Cobol

Page 30: Commercial Uses of Functional Programming

Generators: List Fusion

Page 31: Commercial Uses of Functional Programming

Generators: List Fusion

fibs = 1:1:[ x+y | x <- fibs | y <- tail fibs ]

take 6 (map (*10) fibs) [10,10,20,30,50,80]

Page 32: Commercial Uses of Functional Programming

Generators: List Fusion

fibs = 1:1:[ x+y | x <- fibs | y <- tail fibs ]

take 6 (map (*10) fibs) [10,10,20,30,50,80]

take 6 (map (*5) (map (*2) fibs))[10,10,20,30,50,80]

Page 33: Commercial Uses of Functional Programming

Generators: List Fusion

fibs = 1:1:[ x+y | x <- fibs | y <- tail fibs ]

take 6 (map (*10) fibs) [10,10,20,30,50,80]

take 6 (map (*5) (map (*2) fibs))[10,10,20,30,50,80]

take 6 (map ((*5) . (*2)) fibs)

Page 34: Commercial Uses of Functional Programming

QuickCheck: Property Testing

Page 35: Commercial Uses of Functional Programming

QuickCheck: Property Testing

import Test.QuickCheck prop :: [Int] -> [Int] -> Bool prop xs ys = reverse (xs ++ ys) == reverse xs ++ reverse ys

quickCheck prop -- Failed!

Page 36: Commercial Uses of Functional Programming

QuickCheck: Property Testing

import Test.QuickCheck prop :: [Int] -> [Int] -> Bool prop xs ys = reverse (xs ++ ys) == reverse xs ++ reverse ys

quickCheck prop -- Failed!

reverse xs ++ reverse ys

Page 37: Commercial Uses of Functional Programming

QuickCheck: Property Testing

import Test.QuickCheck prop :: [Int] -> [Int] -> Bool prop xs ys = reverse (xs ++ ys) == reverse xs ++ reverse ys

quickCheck prop -- Failed!

reverse xs ++ reverse ys

quickCheck prop -- Failed!

Page 38: Commercial Uses of Functional Programming

QuickCheck: Property Testing

import Test.QuickCheck prop :: [Int] -> [Int] -> Bool prop xs ys = reverse (xs ++ ys) == reverse xs ++ reverse ys

quickCheck prop -- Failed!

reverse ys ++ reverse xs

quickCheck prop -- Passed!

Page 39: Commercial Uses of Functional Programming

Macros: Multi-Stage Programming

Page 40: Commercial Uses of Functional Programming

Macros: Multi-Stage Programming

import Text.InterpolatedString.Perl6 user = "world" putStrLn [qq| Hello, $user! Your lucky number: { 6*7 } |]

Page 41: Commercial Uses of Functional Programming

2011 20142004

Page 42: Commercial Uses of Functional Programming

2011 20142004

2005

Page 43: Commercial Uses of Functional Programming

2011 20142004

2005 2012

Page 44: Commercial Uses of Functional Programming
Page 45: Commercial Uses of Functional Programming

ES/9000 R46 4CPU, 8GB RAM

50MTWD

Page 46: Commercial Uses of Functional Programming

RS/6000 H70 340MHz 1MTWD

ES/9000 R46 4CPU, 8GB RAM

50MTWD

Page 47: Commercial Uses of Functional Programming

InfoPrint/4000 ID5 1000 PPM 15MTWD

RS/6000 H70 340MHz 1MTWD

ES/9000 R46 4CPU, 8GB RAM

50MTWD

Page 48: Commercial Uses of Functional Programming

InfoPrint/4000 ID5 1000 PPM 15MTWD

RS/6000 H70 340MHz 1MTWD

ES/9000 R46 4CPU, 8GB RAM

50MTWD

Page 49: Commercial Uses of Functional Programming

InfoPrint/4000 ID5 1000 PPM 15MTWD

RS/6000 H70 340MHz 1MTWD

ES/9000 R46 4CPU, 8GB RAM

50MTWDCOBOL RPG

PL/1 REXX SQL

Page 50: Commercial Uses of Functional Programming

InfoPrint/4000 ID5 1000 PPM 15MTWD

RS/6000 H70 340MHz 1MTWD

ES/9000 R46 4CPU, 8GB RAM

50MTWDCOBOL RPG

PL/1 REXX SQL

Page 51: Commercial Uses of Functional Programming

Content Manager OnDemand

Feb 2004

Page 52: Commercial Uses of Functional Programming

Content Manager OnDemand

Feb 2004

Page 53: Commercial Uses of Functional Programming

Content Manager OnDemand

Encode::IBM Parse::AFP

Feb 2004

Page 54: Commercial Uses of Functional Programming

Content Manager OnDemand

Encode::IBM Parse::AFP

Feb 2004

Page 55: Commercial Uses of Functional Programming

Content Manager OnDemand

Encode::IBM Parse::AFP

Feb 2004

Page 56: Commercial Uses of Functional Programming

September 2004

Page 57: Commercial Uses of Functional Programming

September 2004

Page 58: Commercial Uses of Functional Programming

September 2004

Page 59: Commercial Uses of Functional Programming

September 2004

Page 60: Commercial Uses of Functional Programming

September 2004

SAX-style iterators

Page 61: Commercial Uses of Functional Programming

September 2004

SAX-style iteratorsO(n) memory use

Page 62: Commercial Uses of Functional Programming

September 2004

SAX-style iteratorsO(n) memory use

300KB/sec (my laptop)

Page 63: Commercial Uses of Functional Programming

September 2004

SAX-style iteratorsO(n) memory use

300KB/sec (my laptop)30KB/sec (production)

Page 64: Commercial Uses of Functional Programming

September 2004

SAX-style iteratorsO(n) memory use

300KB/sec (my laptop)30KB/sec (production)

Input: 25GB/dayThroughput: 2.5GB/day

Page 65: Commercial Uses of Functional Programming

September 2004

SAX-style iteratorsO(n) memory use

300KB/sec (my laptop)30KB/sec (production)

Input: 25GB/dayThroughput: 2.5GB/day

Deadline:Feb 2005

Page 66: Commercial Uses of Functional Programming

October—November 2004

Page 67: Commercial Uses of Functional Programming

October—November 2004

Page 68: Commercial Uses of Functional Programming

October—November 2004

Page 69: Commercial Uses of Functional Programming

December 2004: Freenode

Page 70: Commercial Uses of Functional Programming

December 2004: Freenode

✤ “Yeah, CosmicRay recently ported GHC to AIX.”

Page 71: Commercial Uses of Functional Programming

December 2004: Freenode

✤ “Yeah, CosmicRay recently ported GHC to AIX.”

✤ “Defining a functor instance as liftM works I'm pretty sure, so… all Monads are Functors (theoretically), instance Monad a => Functor a where fmap = liftM would cover all monads.”

Page 72: Commercial Uses of Functional Programming

December 2004: Freenode

✤ “Yeah, CosmicRay recently ported GHC to AIX.”

✤ “Defining a functor instance as liftM works I'm pretty sure, so… all Monads are Functors (theoretically), instance Monad a => Functor a where fmap = liftM would cover all monads.”✤ “Elaborate please? <- have only learned haskell for 5 days…”

Page 73: Commercial Uses of Functional Programming

December 2004: Freenode

✤ “Yeah, CosmicRay recently ported GHC to AIX.”

✤ “Defining a functor instance as liftM works I'm pretty sure, so… all Monads are Functors (theoretically), instance Monad a => Functor a where fmap = liftM would cover all monads.”✤ “Elaborate please? <- have only learned haskell for 5 days…”

✤ “unsafeInterleaveIO is the best thing since sliced bread.”

Page 74: Commercial Uses of Functional Programming

December 2004: Freenode

✤ “Yeah, CosmicRay recently ported GHC to AIX.”

✤ “Defining a functor instance as liftM works I'm pretty sure, so… all Monads are Functors (theoretically), instance Monad a => Functor a where fmap = liftM would cover all monads.”✤ “Elaborate please? <- have only learned haskell for 5 days…”

✤ “unsafeInterleaveIO is the best thing since sliced bread.”

✤ “What do I do with a compiler with exploding brains?”

Page 75: Commercial Uses of Functional Programming

December 2004: Freenode

✤ “Yeah, CosmicRay recently ported GHC to AIX.”

✤ “Defining a functor instance as liftM works I'm pretty sure, so… all Monads are Functors (theoretically), instance Monad a => Functor a where fmap = liftM would cover all monads.”✤ “Elaborate please? <- have only learned haskell for 5 days…”

✤ “unsafeInterleaveIO is the best thing since sliced bread.”

✤ “What do I do with a compiler with exploding brains?”

✤ “Haskell has a solid niche as a PhD generator :)”

Page 76: Commercial Uses of Functional Programming

January 2005

Page 77: Commercial Uses of Functional Programming

January 2005

✤ OpenAFP.hs delivered —

Page 78: Commercial Uses of Functional Programming

Input: 25GB/dayThroughput: 500GB/day

DOM-Style selectorsO(1) Memory Use!

January 2005

✤ OpenAFP.hs delivered —

Page 79: Commercial Uses of Functional Programming

Input: 25GB/dayThroughput: 500GB/day

DOM-Style selectorsO(1) Memory Use!

January 2005

✤ OpenAFP.hs delivered — ✤ NTD$3k/hr * 3 months

Page 80: Commercial Uses of Functional Programming

Input: 25GB/dayThroughput: 500GB/day

DOM-Style selectorsO(1) Memory Use!

January 2005

✤ OpenAFP.hs delivered — ✤ NTD$3k/hr * 3 months

✤ “You don't need category theory, you need BC Pierce's 'Types and Programming Languages’”

Page 81: Commercial Uses of Functional Programming

Input: 25GB/dayThroughput: 500GB/day

DOM-Style selectorsO(1) Memory Use!

January 2005

✤ OpenAFP.hs delivered — ✤ NTD$3k/hr * 3 months

✤ “You don't need category theory, you need BC Pierce's 'Types and Programming Languages’”

Page 82: Commercial Uses of Functional Programming

Input: 25GB/dayThroughput: 500GB/day

DOM-Style selectorsO(1) Memory Use!

January 2005

✤ OpenAFP.hs delivered — ✤ NTD$3k/hr * 3 months

✤ “You don't need category theory, you need BC Pierce's 'Types and Programming Languages’”

✤ “My target language is huge. I need all the help I can get :)”

Page 83: Commercial Uses of Functional Programming

2005: PugsFeb 1: Started on Freenode #haskellLambdas & Camels joined in #perl6Specification revised, iterated, testedConcurrency, Coroutines, Commit Bits!

Page 84: Commercial Uses of Functional Programming

2006: Erdős ingYAPC: Worst is Best on targeting JSOOPSLA: Reconciling the IrreconcilableSucceeded by Moose & RakudoPerl 5 runtime became Modern PerlConcluding talk: Optimizing for Fun

楽⼟土

Page 85: Commercial Uses of Functional Programming

2007: S-TeamNew tech stack: Jifty, Moose, and GHCOpenAFP Utilities: Report Generation, Extraction, Management, Distribution, Conversion…Enhanced & eventually replaced IBM OnDemand with PDF-based workflow

Page 86: Commercial Uses of Functional Programming

2008: SocialtextMidlife crisis — Becoming a PHB?Hierarchical organization & culture — can we change that with technology?Decided to telecommute full time: - ST (social workplace), or - FB (social media)?

Page 87: Commercial Uses of Functional Programming

2009: SocialCalcWorked with Dan Bricklin & friends

Summarized into three book chapters: - Architecture of Open Source Applications - Performance of Open Source Applications - 500 lines or less (in progress)

EtherCalc: Backend of g0v.today

Page 88: Commercial Uses of Functional Programming

2010: AppleCloud Service Localization

Everything under NDA……with one single exception

Page 89: Commercial Uses of Functional Programming

May 2011

Page 90: Commercial Uses of Functional Programming

May 2011

✤ “Can you write me some code that takes a regular expression and enumerates the domain it accepts?”

Page 91: Commercial Uses of Functional Programming

May 2011

✤ “Can you write me some code that takes a regular expression and enumerates the domain it accepts?”

✤ “I think I can do this with the yices2 SMT solver and the SBV Haskell library to turn regexes into satisfiability problems, and so we can get all examples.

Page 92: Commercial Uses of Functional Programming

May 2011

✤ “Can you write me some code that takes a regular expression and enumerates the domain it accepts?”

✤ “I think I can do this with the yices2 SMT solver and the SBV Haskell library to turn regexes into satisfiability problems, and so we can get all examples.

✤ But this is too much fun for an one-off script… Would you mind if I do this pro bono so I can release it into public domain? :-)”

Page 93: Commercial Uses of Functional Programming

SMT Constraint Solving

Page 94: Commercial Uses of Functional Programming

SMT Constraint Solving

✤ Genex: Regex as predicates on integer variables

/([AB]C)\1/

Page 95: Commercial Uses of Functional Programming

SMT Constraint Solving

✤ Genex: Regex as predicates on integer variables

✤ Solve for [x, y, z, w]: /([AB]C)\1/

(x=‘A’ ∨ x=‘B’) ∧ (y=‘C’) ∧

(z=x) ∧ (w=y)

Page 96: Commercial Uses of Functional Programming

SMT Constraint Solving

✤ Genex: Regex as predicates on integer variables

✤ Solve for [x, y, z, w]:

✤ “ACAC”“BCBC”

/([AB]C)\1/

(x=‘A’ ∨ x=‘B’) ∧ (y=‘C’) ∧

(z=x) ∧ (w=y)

Page 97: Commercial Uses of Functional Programming

SMT Constraint Solving

✤ Genex: Regex as predicates on integer variables

✤ Solve for [x, y, z, w]:

✤ “ACAC”“BCBC”

✤ Supports \b \1 ^ $

/([AB]C)\1/

(x=‘A’ ∨ x=‘B’) ∧ (y=‘C’) ∧

(z=x) ∧ (w=y)

Page 98: Commercial Uses of Functional Programming

A Regular Crossword

(ND|ET|IN)[^X]*

(DI|NS|TH|OM)*

.*(IN|SE|HI)

[CHMNOR]*I[CHM

NOR]*

C*MC(CCC|MM)*

([^EMC]|EM

)*

[CEIMU]*OH[AEMOR]*

[AM]*CM

(RC)*R?

N.*X.X.X.*E

.*XHCR.*X.*

(RR|HHH)*.?

(...?)\1*

.*XEXM*

[CR]*

[^C]*MMM[^C]*

(E|CR|MN)*

([^X]|XCC)*

.*OXR.*.*PRR.*DDC.*

R*D*M*

.*(.)(.)(.)(.)\4\3\2\1.*

(RX|[^R])*

.*SE.*UE.*.*LR.*RL.*

(S|MM|HHH)*

.*G.*V.*H.*

[^C]*[^R]*III.*

(HHX|[^HX])*

.(C|HH)*

.*DD.*CCM.*

P+(..)\1.*(O|RHH|MM)*

([^MC]|M

M|CC)*

.*(.)C\1X\1.*

F.*[AO].*[AO].*

[^M]*M[^M]*

.*H.*H.*

.*

.*

Page 99: Commercial Uses of Functional Programming

A Regular Crossword

✤ Source: MIT Mystery Hunt 2013

(ND|ET|IN)[^X]*

(DI|NS|TH|OM)*

.*(IN|SE|HI)

[CHMNOR]*I[CHM

NOR]*

C*MC(CCC|MM)*

([^EMC]|EM

)*

[CEIMU]*OH[AEMOR]*

[AM]*CM

(RC)*R?

N.*X.X.X.*E

.*XHCR.*X.*

(RR|HHH)*.?

(...?)\1*

.*XEXM*

[CR]*

[^C]*MMM[^C]*

(E|CR|MN)*

([^X]|XCC)*

.*OXR.*.*PRR.*DDC.*

R*D*M*

.*(.)(.)(.)(.)\4\3\2\1.*

(RX|[^R])*

.*SE.*UE.*.*LR.*RL.*

(S|MM|HHH)*

.*G.*V.*H.*

[^C]*[^R]*III.*

(HHX|[^HX])*

.(C|HH)*

.*DD.*CCM.*

P+(..)\1.*(O|RHH|MM)*

([^MC]|M

M|CC)*

.*(.)C\1X\1.*

F.*[AO].*[AO].*

[^M]*M[^M]*

.*H.*H.*

.*

.*

Page 100: Commercial Uses of Functional Programming

A Regular Crossword

✤ Source: MIT Mystery Hunt 2013

✤ Solved in ~40 lines of Haskell with Genex!

(ND|ET|IN)[^X]*

(DI|NS|TH|OM)*

.*(IN|SE|HI)

[CHMNOR]*I[CHM

NOR]*

C*MC(CCC|MM)*

([^EMC]|EM

)*

[CEIMU]*OH[AEMOR]*

[AM]*CM

(RC)*R?

N.*X.X.X.*E

.*XHCR.*X.*

(RR|HHH)*.?

(...?)\1*

.*XEXM*

[CR]*

[^C]*MMM[^C]*

(E|CR|MN)*

([^X]|XCC)*

.*OXR.*.*PRR.*DDC.*

R*D*M*

.*(.)(.)(.)(.)\4\3\2\1.*

(RX|[^R])*

.*SE.*UE.*.*LR.*RL.*

(S|MM|HHH)*

.*G.*V.*H.*

[^C]*[^R]*III.*

(HHX|[^HX])*

.(C|HH)*

.*DD.*CCM.*

P+(..)\1.*(O|RHH|MM)*

([^MC]|M

M|CC)*

.*(.)C\1X\1.*

F.*[AO].*[AO].*

[^M]*M[^M]*

.*H.*H.*

.*

.*

Page 101: Commercial Uses of Functional Programming

A Regular Crossword

✤ Source: MIT Mystery Hunt 2013

✤ Solved in ~40 lines of Haskell with Genex!

(ND|ET|IN)[^X]*

(DI|NS|TH|OM)*

.*(IN|SE|HI)

[CHMNOR]*I[CHM

NOR]*

C*MC(CCC|MM)*

([^EMC]|EM

)*

[CEIMU]*OH[AEMOR]*

[AM]*CM

(RC)*R?

N.*X.X.X.*E

.*XHCR.*X.*

(RR|HHH)*.?

(...?)\1*

.*XEXM*

[CR]*

[^C]*MMM[^C]*

(E|CR|MN)*

([^X]|XCC)*

.*OXR.*.*PRR.*DDC.*

R*D*M*

.*(.)(.)(.)(.)\4\3\2\1.*

(RX|[^R])*

.*SE.*UE.*.*LR.*RL.*

(S|MM|HHH)*

.*G.*V.*H.*

[^C]*[^R]*III.*

(HHX|[^HX])*

.(C|HH)*

.*DD.*CCM.*

P+(..)\1.*(O|RHH|MM)*

([^MC]|M

M|CC)*

.*(.)C\1X\1.*

F.*[AO].*[AO].*

[^M]*M[^M]*

.*H.*H.*

.*

.*

N H P E H A SD I O M O M T H

F O X N X A X P HM M O M M M M R H H

M C X N M M C R X E MC M C C C C M M M M M MH R X R C M I I I H X L SO R E O R E O R E O R EV C X C C H H M X C CR R R R H H H R R UN C X D X E X L ER R D D M M M MG C C H H C C

Page 102: Commercial Uses of Functional Programming

SmallCheck: Enumerated Series

Page 103: Commercial Uses of Functional Programming

SmallCheck: Enumerated Series

✤ Type-Level Literals: Numbers and Symbols

xs :: [Matching "a?b?c?"] xs = list 100 series

[,a,b,ab,c,ac,bc,abc]

Page 104: Commercial Uses of Functional Programming

SmallCheck: Enumerated Series

✤ Type-Level Literals: Numbers and Symbols

✤ Check properties for all strings matching a regex

xs :: [Matching "a?b?c?"] xs = list 100 series

[,a,b,ab,c,ac,bc,abc]

Page 105: Commercial Uses of Functional Programming

QuickCheck: Random Sampling

Page 106: Commercial Uses of Functional Programming

QuickCheck: Random Sampling

✤ Regular Expressions and XML Schemata:

generate (matching rfc2822) "9%[email protected]"

Page 107: Commercial Uses of Functional Programming

QuickCheck: Random Sampling

✤ Regular Expressions and XML Schemata:

generate (matching rfc2822) "9%[email protected]"

putStr . showXmlTree =<< generate . matchingRNG =<< loadRNG “book.rng”

<?xml version="1.0" encoding="UTF-8"?><book>

<author>[email protected]</author>

<author>[email protected]</author>

<author>[email protected]</author>

</book>

Page 108: Commercial Uses of Functional Programming

2012: LiveScriptFeb 1: @gkz forked @satyr’s fork of .coffee

“Like a smaller language within Perl 6, struggling to get out…”

May 1: ST joined PeopleFluent at Bedford

June 1: CoffeeRedux by @michaelficarra

Launched JS2LS: @clkao, @gkz, @mpgutta

Coco

Page 109: Commercial Uses of Functional Programming

2013: MoeDictFeb 1: Revised MoE Dictionary in HTML5

- Every word linked to its definition

- Fair Use and CC0 as legal frameworks

moedict.tw: Android, iOS, Firefox OS

Holo, Hakka, Cross-Strait Language DB

萌典

Page 110: Commercial Uses of Functional Programming

May 2014: CUFP Program Committee

Page 111: Commercial Uses of Functional Programming

May 2014: CUFP Program Committee

✤ “I enjoyed @simonmar's slides The Haxl Project at Facebook and the related /r/haskell discussions.

Page 112: Commercial Uses of Functional Programming

May 2014: CUFP Program Committee

✤ “I enjoyed @simonmar's slides The Haxl Project at Facebook and the related /r/haskell discussions.

✤ It’s a reasonably easy-to-understand Commercial Use of Functional Programming that I plan to talk about in my FLOLAC’14 talk.

Page 113: Commercial Uses of Functional Programming

May 2014: CUFP Program Committee

✤ “I enjoyed @simonmar's slides The Haxl Project at Facebook and the related /r/haskell discussions.

✤ It’s a reasonably easy-to-understand Commercial Use of Functional Programming that I plan to talk about in my FLOLAC’14 talk.

✤ Would it make sense to invite @simonmar to the CUFP keynote?”

Page 114: Commercial Uses of Functional Programming

Fighting Spam with Pure Functions

Page 116: Commercial Uses of Functional Programming

Fighting Spam with Pure Functions

✤ Nov 2012: Simon Marlow joins Facebook

✤ Jan 2013: FXL — Subset of ML, interpreted in C++

Page 117: Commercial Uses of Functional Programming

Fighting Spam with Pure Functions

✤ Nov 2012: Simon Marlow joins Facebook

✤ Jan 2013: FXL — Subset of ML, interpreted in C++

If (Average(Map(Reputation, PreviousSharedUrls(User, 5))) < 0) Then [WarnUser, LogRequest] Else []

Page 118: Commercial Uses of Functional Programming

Fighting Spam with Pure Functions

✤ Nov 2012: Simon Marlow joins Facebook

✤ Jan 2013: FXL — Subset of ML, interpreted in C++

✤ Aug 2013: Haxl compiler implemented in GHC

Page 119: Commercial Uses of Functional Programming

Fighting Spam with Pure Functions

✤ Nov 2012: Simon Marlow joins Facebook

✤ Jan 2013: FXL — Subset of ML, interpreted in C++

✤ Aug 2013: Haxl compiler implemented in GHC

✤ Jun 2014: Deployed and Open Sourced

Page 120: Commercial Uses of Functional Programming

Fighting Spam with Pure Functions

✤ Nov 2012: Simon Marlow joins Facebook

✤ Jan 2013: FXL — Subset of ML, interpreted in C++

✤ Aug 2013: Haxl compiler implemented in GHC

✤ Jun 2014: Deployed and Open Sourced

✤ Sep 2014: There is no fork @ ICFP

Page 121: Commercial Uses of Functional Programming

FXL on Haxl

If (Average(Map(Reputation, PreviousSharedUrls(User, 5))) < 0) Then [WarnUser, LogRequest] Else []

Page 122: Commercial Uses of Functional Programming

FXL on Haxl

If (Average(Map(Reputation, PreviousSharedUrls(User, 5))) < 0) Then [WarnUser, LogRequest] Else []

Page 123: Commercial Uses of Functional Programming

FXL on Haxl

If (Average(Map(Reputation, PreviousSharedUrls(User, 5))) < 0) Then [WarnUser, LogRequest] Else []

Marlow et al, The Haxl Project at Facebook

Page 124: Commercial Uses of Functional Programming

FXL on Haxl

If (Average(Map(Reputation, PreviousSharedUrls(User, 5))) < 0) Then [WarnUser, LogRequest] Else []

Marlow et al, The Haxl Project at Facebook

Page 125: Commercial Uses of Functional Programming

Concurrency & Caching

Page 126: Commercial Uses of Functional Programming

Concurrency & Caching

✤ With the Applicative Do macro:

fun :: Haxl String fun = [ado| x <- fetch “A” y <- fetch “B” z <- fetch y x ++ y ++ z |]

Page 127: Commercial Uses of Functional Programming

Concurrency & Caching

✤ With the Applicative Do macro:

fun :: Haxl String fun = [ado| x <- fetch “A” y <- fetch “B” z <- fetch y x ++ y ++ z |]

fetch “A”

fetch “B”

Page 128: Commercial Uses of Functional Programming

Concurrency & Caching

✤ With the Applicative Do macro:

fun :: Haxl String fun = [ado| x <- fetch “A” y <- fetch “B” z <- fetch y x ++ y ++ z |]

fetch “A”

fetch “B”

H A

Page 129: Commercial Uses of Functional Programming

Concurrency & Caching

✤ With the Applicative Do macro:

fun :: Haxl String fun = [ado| x <- fetch “A” y <- fetch “B” z <- fetch y x ++ y ++ z |]

fetch “A”

fetch “B”

H A

fetch “A”

H

cached

Page 130: Commercial Uses of Functional Programming

Concurrency & Caching

✤ With the Applicative Do macro:

fun :: Haxl String fun = [ado| x <- fetch “A” y <- fetch “B” z <- fetch y x ++ y ++ z |]

fetch “A”

fetch “B”

H A++

fetch “A”

H

cached

++

HAH

Page 131: Commercial Uses of Functional Programming

Recap

Page 132: Commercial Uses of Functional Programming

Recap

✤ Generators: List Fusion

Page 133: Commercial Uses of Functional Programming

Recap

✤ Generators: List Fusion

✤ QuickCheck: Property Testing

Page 134: Commercial Uses of Functional Programming

Recap

✤ Generators: List Fusion

✤ QuickCheck: Property Testing

✤ Macros: Multi-Stage Programming

Page 135: Commercial Uses of Functional Programming

main :: IO ()Functional Programming as a means —

Page 136: Commercial Uses of Functional Programming

main :: IO aFunctional Programming as a means —

Page 137: Commercial Uses of Functional Programming

main :: IO aFunctional Programming as a means —

newtype IO a =

IO ( State# RealWorld

-> (# State# RealWorld, a #))

Page 138: Commercial Uses of Functional Programming

main :: IO aFunctional Programming as a means —

newtype IO a =

IO ( State# RealWorld

-> (# State# RealWorld, a #))

main :: State# RealWorld

-> (# State# RealWorld, a #)

Page 139: Commercial Uses of Functional Programming

main :: IO aFunctional Programming as a means —

newtype IO a =

IO ( State# RealWorld

-> (# State# RealWorld, a #))

main :: State# RealWorld

-> (# State# RealWorld, a #)

to observe the world,

Page 140: Commercial Uses of Functional Programming

main :: IO aFunctional Programming as a means —

newtype IO a =

IO ( State# RealWorld

-> (# State# RealWorld, a #))

main :: State# RealWorld

-> (# State# RealWorld, a #)

to observe the world,to change it, and to create a new value.