SlideShare a Scribd company logo
1 of 23
Download to read offline
Haskell, Scala, F#
Are they worth the fuss?
My Background
• B.Tech. IIT-Bombay. Computer Science.
• Ph.D. USC. Algorithmic Algebra.
• VP. Goldman Sachs. Trading Strategist.
• Managing Director. Morgan Stanley.
• Founder & C.E.O. ZLemma (A Tech Startup).
Haskell, Scala, F#
• A different way of thinking about coding
• Functional Programming is just one feature
• High productivity (not easy to produce bugs)
• Elegant and expressive (readable, maintainable)
• Enjoyable and Addictive!
A different way of thinking
• The way we think when we do Math
• It’s not about objects, state and “recipes”
• It’s about (in Math-speak) sets, functions, compositions
• Express what you want to do, not “how to do”
• Elite programmers are influencing a cultural shift
More than just FP
• FP means stateless code & higher-order functions
• {Haskell, Scala, F#} -> many other nice things
• Static but Inferred Typing. Hence, safe yet succinct
• Algebraic Data Types & Pattern Matching
• The M word …
Stateless code
• Everything is a const. Banish the word “variable”
• So: no loops, no reassignments, no object edits
• Instead: map, fold, recursion, algebraic data types
• Many small functions delegating to other functions
• “State is the root cause of bugs” #MadeUpQuote
def isprime(n):
if n == 2:
return True
if n == 1 or n % 2 == 0:
return False
max = n**0.5+1
i = 3
while i <= max:
if n % i == 0:
return False
i+=2
return 1
Python done badly
def isPrime(n):
if n == 1:
return False
else:
return all(n % i != 0 for i in range(2, int(sqrt(n)) + 1) if isPrime(i))
Python done well
But what about typing?
let notFactorOf n =

fun i -> n % i <> 0



let intSqrt n =

(int << sqrt << float) n



let rec isPrime = function

| 1 -> false

| n -> Seq.forall (notFactorOf n) (seq {for i in 2 .. (intSqrt n)
do if isPrime i then yield i})

Same code in F#
Higher-order Functions
• Think of functions as a “generalization of data”
• Functions accepting and/or returning function
• Function composition (chaining)
• Exploit the power of lambdas and currying
• Laziness and memoization
class NumSet(object):
def __init__(self):
self.__data__ = None
def __calc__(self):
return self
def get_calc(self):
if not self.__data__:
self.__data__ = self.__calc__()
return self.__data__
class NumSetLeaf(NumSet):
def __init__(self, low, mid, high):
super(NumSetLeaf, self).__init__()
self.low = low
self.mid = mid
self.high = high
self.triple = (self.low, self.mid, self.high)
class NumSetOp(NumSet):
def __init__(self, fl, args):
super(NumSetOp, self).__init__()
self.fl = fl
self.args = args
def __calc__(self):
lows, mids, highs = zip(*[x.get_calc().triple for x in self.args])
fl = self.fl
return NumSetLeaf(fl(lows), fl(mids), fl(highs))
class NumSetSum(NumSetOp):
def __init__(self, args):
super(NumSetSum, self).__init__(sum, args)


Can Python “Haskell”?
class NumSetUnaryOp(NumSetOp):
def __init__(self, f1, arg):
super(NumSetUnaryOp, self).__init__(lambda l1, f1=f1: f1(*l1), [arg])
self.f1 = f1
self.arg = arg
class NumSetScale(NumSetUnaryOp):
def __init__(self, arg, k):
super(NumSetScale, self).__init__(lambda x, k=k: x * k, arg)
self.k = k
class NumSetBinaryOp(NumSetOp):
def __init__(self, f2, arg1, arg2):
super(NumSetBinaryOp, self).__init__(lambda l2, f2=f2: f2(*l2), [arg1, arg2])
self.f2 = f2
self.arg1 = arg1
self.arg2 = arg2
class NumSetPlus(NumSetBinaryOp):
def __init__(self, arg1, arg2):
super(NumSetPlus, self).__init__(lambda x, y: x + y, arg1, arg2)
class NumSetMult(NumSetBinaryOp):
def __init__(self, arg1, arg2):
super(NumSetMult, self).__init__(lambda x, y: x * y, arg1, arg2)
l1 = NumSetLeaf(0.9, 0.92, 0.95
l2 = NumSetLeaf(0.8, 0.85, 0.9)
l3 = NumSetLeaf(0.6, 0.7, 0.8)
k = 0.6
l4 = NumSetPlus(NumSetScale(l1, k), NumSetScale(l2, 1.0 - k))
l5 = NumSetScale(NumSetSum([l4, l2, l3]), 0.3)
Can Python “Haskell”?
Infered Typing
• The best of both worlds
The rigor and safety of static typing
Type inference lends syntactic lightness
• Most coding errors are caught as one types code
• Visualization of typing makes one think better
• Scripting-style, rapid prototyping, REPL
Algebraic Data Types
• Elegant (recursive) way to express data structures
• Makes writing of algorithms very easy and natural
• Pattern-matching on edge cases and types
• No more ugly/dangerous if-elseif, switch/case code
• Type/structural safety. Hard to introduce bugs.
type color = R | B
type 'a tree =
| E
| T of color * 'a tree * 'a * 'a tree
module Tree =
let hd = function
| E -> failwith "empty"
| T(c, l, x, r) -> x
let left = function
| E -> failwith "empty"
| T(c, l, x, r) -> l
let right = function
| E -> failwith "empty"
| T(c, l, x, r) -> r
let rec exists item = function
| E -> false
| T(c, l, x, r) ->
if item = x then true
elif item < x then exists item l
else exists item r
let balance = function (* Red nodes in relation to black root *)
| B, T(R, T(R, a, x, b), y, c), z, d (* Left, left *)
| B, T(R, a, x, T(R, b, y, c)), z, d (* Left, right *)
| B, a, x, T(R, T(R, b, y, c), z, d) (* Right, left *)
| B, a, x, T(R, b, y, T(R, c, z, d)) (* Right, right *)
-> T(R, T(B, a, x, b), y, T(B, c, z, d))
| c, l, x, r -> T(c, l, x, r)
let insert item tree =
let rec ins = function
| E -> T(R, E, item, E)
| T(c, a, y, b) as node ->
if item = y then node
elif item < y then balance(c, ins a, y, b)
else balance(c, a, y, ins b)
match ins tree with
| E -> failwith "Should never return empty from an insert"
| T(_, l, x, r) -> T(B, l, x, r)
Red-Black Tree in F#
Make Data, Not Code
• Data-driven coding (parametric algorithms)
• Structured data framework controls your algorithms
• A system where key logic is in data, not code
• User wants a lot of control => Give him a DSL
• Plug & Play system => Bring Your Own Data (DSL)
DSL
• Internal versus External
• External: End-User DSL versus Dev DSL
• Internal: Syntactic Sugar for clean, controlled code
• Graphical representation of DSL => Functional
• Well-typed, Functional DSL => Happy Algorithms!
The M Word …
• Monads - not just for “side-effects computing”
• Functional way of doing imperative/sequential logic
• Define Domains, Ranges, Compositions (Chains)
• Sounds complex but yields clean, bug-free code
• 4 types of X => M(X) monadic “Range Expansion”
• g: A -> M(B), f: B -> M(C). How to get f o g: A -> M(C)
4 types of Monads
• Failure: A -> Maybe(B), B -> Maybe(C).
• Configurations: A -> Settings(B), B -> Settings(C).
• Uncertainty: A -> Power(B), B -> Power(C).
• Side-Effects: A -> IO(B), B -> IO(C)
• Just figure out the bind and unit methods for each
• Chain with bind and unit, and it’s all automatic!
type Maybe<‘a> =
| Just of 'a
| Nothing
let Return (x: 'a) : Maybe<'a> =
Just(x)
let Bind (mx: Maybe<'b>) (f: 'b -> Maybe<'c>) : Maybe<'c> =
match mx with
| Just(x) -> f x
| Nothing -> Nothing
Failure: “Maybe” monad
Maybe(X) is an algebraic data type that can be X or “Error”
g: A -> Maybe(B)
f: B -> Maybe(C)
How to produce f o g : A -> Maybe(C)
let Return (x: 'a) : (‘s -> ‘a) =
fun _ -> x
let Bind (mx: ’s -> ‘b) (f: 'b -> (’s -> ‘c)) : (’s -> ‘c) =
fun y -> f (mx y) y
Configurations: “Settings” monad
Settings(X) is a function from a “Settings” type to X
g: A -> Settings(B)
f: B -> Settings(C)
How to produce f o g : A -> Settings(C)
let Return (x: 'a) : Set<‘a> =
set [x]
let Bind (mx: Set<‘b>) (f: 'b -> Set<‘c>) : Set<‘c> =
set [for x in mx do yield! f x]
Uncertainty: “Power” monad
Power(X) is the power set of X (the set of all subsets of X)
g: A -> Power(B)
f: B -> Power(C)
How to produce f o g : A -> Power(C)
let Return (x: 'a) : (unit -> ‘a) =
fun () -> x
let Bind (mx: unit -> ‘b) (f: 'b -> unit -> ‘c) : (unit -> ‘c) =
f (mx())
Side-effects: “IO” monad
IO(X) is a side-effects-function from Null (i.e., no args) to X
g: A -> IO(B)
f: B -> IO(C)
How to produce f o g : A -> IO(C)

More Related Content

What's hot

An Introduction to Functional Programming - DeveloperUG - 20140311
An Introduction to Functional Programming - DeveloperUG - 20140311An Introduction to Functional Programming - DeveloperUG - 20140311
An Introduction to Functional Programming - DeveloperUG - 20140311Andreas Pauley
 
Functional programming with haskell
Functional programming with haskellFunctional programming with haskell
Functional programming with haskellfaradjpour
 
Monoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsMonoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsPhilip Schwarz
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsDebasish Ghosh
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 
Reasoning about laziness
Reasoning about lazinessReasoning about laziness
Reasoning about lazinessJohan Tibell
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS ResponsibilitiesBrendan Eich
 
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...Doris Chen
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance HaskellJohan Tibell
 
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaFunctional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaPhilip Schwarz
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Mattersromanandreg
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldWerner Hofstra
 
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Philip Schwarz
 
Extensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScriptExtensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScriptBrendan Eich
 
Introduction to programming in scala
Introduction to programming in scalaIntroduction to programming in scala
Introduction to programming in scalaAmuhinda Hungai
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...Philip Schwarz
 
Comparing Haskell & Scala
Comparing Haskell & ScalaComparing Haskell & Scala
Comparing Haskell & ScalaMartin Ockajak
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class PatternsJohn De Goes
 

What's hot (20)

An Introduction to Functional Programming - DeveloperUG - 20140311
An Introduction to Functional Programming - DeveloperUG - 20140311An Introduction to Functional Programming - DeveloperUG - 20140311
An Introduction to Functional Programming - DeveloperUG - 20140311
 
Functional programming with haskell
Functional programming with haskellFunctional programming with haskell
Functional programming with haskell
 
Monoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsMonoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and Cats
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain Models
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Web futures
Web futuresWeb futures
Web futures
 
Reasoning about laziness
Reasoning about lazinessReasoning about laziness
Reasoning about laziness
 
Syntaxdirected
SyntaxdirectedSyntaxdirected
Syntaxdirected
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS Responsibilities
 
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaFunctional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereld
 
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
 
Extensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScriptExtensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScript
 
Introduction to programming in scala
Introduction to programming in scalaIntroduction to programming in scala
Introduction to programming in scala
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
Comparing Haskell & Scala
Comparing Haskell & ScalaComparing Haskell & Scala
Comparing Haskell & Scala
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class Patterns
 

Viewers also liked

The Newsvendor meets the Options Trader
The Newsvendor meets the Options TraderThe Newsvendor meets the Options Trader
The Newsvendor meets the Options TraderAshwin Rao
 
Abstract Algebra in 3 Hours
Abstract Algebra in 3 HoursAbstract Algebra in 3 Hours
Abstract Algebra in 3 HoursAshwin Rao
 
OmniChannelNewsvendor
OmniChannelNewsvendorOmniChannelNewsvendor
OmniChannelNewsvendorAshwin Rao
 
IIT Bombay - First Steps to a Successful Career
IIT Bombay - First Steps to a Successful CareerIIT Bombay - First Steps to a Successful Career
IIT Bombay - First Steps to a Successful CareerAshwin Rao
 
Category Theory made easy with (ugly) pictures
Category Theory made easy with (ugly) picturesCategory Theory made easy with (ugly) pictures
Category Theory made easy with (ugly) picturesAshwin Rao
 
Careers outside Academia - USC Computer Science Masters and Ph.D. Students
Careers outside Academia - USC Computer Science Masters and Ph.D. StudentsCareers outside Academia - USC Computer Science Masters and Ph.D. Students
Careers outside Academia - USC Computer Science Masters and Ph.D. StudentsAshwin Rao
 
Career Advice at University College of London, Mathematics Department.
Career Advice at University College of London, Mathematics Department.Career Advice at University College of London, Mathematics Department.
Career Advice at University College of London, Mathematics Department.Ashwin Rao
 
Pseudo and Quasi Random Number Generation
Pseudo and Quasi Random Number GenerationPseudo and Quasi Random Number Generation
Pseudo and Quasi Random Number GenerationAshwin Rao
 
Careers in Quant Finance talk at UCLA Financial Engineering
Careers in Quant Finance talk at UCLA Financial EngineeringCareers in Quant Finance talk at UCLA Financial Engineering
Careers in Quant Finance talk at UCLA Financial EngineeringAshwin Rao
 
Introduction to Risk-Neutral Pricing
Introduction to Risk-Neutral PricingIntroduction to Risk-Neutral Pricing
Introduction to Risk-Neutral PricingAshwin Rao
 
Columbia CS - Roles in Quant Finance
Columbia CS - Roles in Quant Finance Columbia CS - Roles in Quant Finance
Columbia CS - Roles in Quant Finance Ashwin Rao
 
Stanford FinMath - Careers in Quant Finance
Stanford FinMath - Careers in Quant FinanceStanford FinMath - Careers in Quant Finance
Stanford FinMath - Careers in Quant FinanceAshwin Rao
 
Berkeley Financial Engineering - Guidance on Careers in Quantitative Finance
Berkeley Financial Engineering - Guidance on Careers in Quantitative FinanceBerkeley Financial Engineering - Guidance on Careers in Quantitative Finance
Berkeley Financial Engineering - Guidance on Careers in Quantitative FinanceAshwin Rao
 
Introduction to Stochastic calculus
Introduction to Stochastic calculusIntroduction to Stochastic calculus
Introduction to Stochastic calculusAshwin Rao
 
Careers in Quant Finance - IIT Delhi
Careers in Quant Finance - IIT DelhiCareers in Quant Finance - IIT Delhi
Careers in Quant Finance - IIT DelhiAshwin Rao
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyMartin Odersky
 
Risk Pooling sensitivity to Correlation
Risk Pooling sensitivity to CorrelationRisk Pooling sensitivity to Correlation
Risk Pooling sensitivity to CorrelationAshwin Rao
 
Fitness 101 - Mumbai
Fitness 101 - MumbaiFitness 101 - Mumbai
Fitness 101 - MumbaiAshwin Rao
 
HOW can India's Parliament function better?
HOW can India's Parliament function better?HOW can India's Parliament function better?
HOW can India's Parliament function better?Yogesh Upadhyaya
 
Zinnov zones - Digital in Retail
Zinnov zones - Digital in RetailZinnov zones - Digital in Retail
Zinnov zones - Digital in RetailZinnov
 

Viewers also liked (20)

The Newsvendor meets the Options Trader
The Newsvendor meets the Options TraderThe Newsvendor meets the Options Trader
The Newsvendor meets the Options Trader
 
Abstract Algebra in 3 Hours
Abstract Algebra in 3 HoursAbstract Algebra in 3 Hours
Abstract Algebra in 3 Hours
 
OmniChannelNewsvendor
OmniChannelNewsvendorOmniChannelNewsvendor
OmniChannelNewsvendor
 
IIT Bombay - First Steps to a Successful Career
IIT Bombay - First Steps to a Successful CareerIIT Bombay - First Steps to a Successful Career
IIT Bombay - First Steps to a Successful Career
 
Category Theory made easy with (ugly) pictures
Category Theory made easy with (ugly) picturesCategory Theory made easy with (ugly) pictures
Category Theory made easy with (ugly) pictures
 
Careers outside Academia - USC Computer Science Masters and Ph.D. Students
Careers outside Academia - USC Computer Science Masters and Ph.D. StudentsCareers outside Academia - USC Computer Science Masters and Ph.D. Students
Careers outside Academia - USC Computer Science Masters and Ph.D. Students
 
Career Advice at University College of London, Mathematics Department.
Career Advice at University College of London, Mathematics Department.Career Advice at University College of London, Mathematics Department.
Career Advice at University College of London, Mathematics Department.
 
Pseudo and Quasi Random Number Generation
Pseudo and Quasi Random Number GenerationPseudo and Quasi Random Number Generation
Pseudo and Quasi Random Number Generation
 
Careers in Quant Finance talk at UCLA Financial Engineering
Careers in Quant Finance talk at UCLA Financial EngineeringCareers in Quant Finance talk at UCLA Financial Engineering
Careers in Quant Finance talk at UCLA Financial Engineering
 
Introduction to Risk-Neutral Pricing
Introduction to Risk-Neutral PricingIntroduction to Risk-Neutral Pricing
Introduction to Risk-Neutral Pricing
 
Columbia CS - Roles in Quant Finance
Columbia CS - Roles in Quant Finance Columbia CS - Roles in Quant Finance
Columbia CS - Roles in Quant Finance
 
Stanford FinMath - Careers in Quant Finance
Stanford FinMath - Careers in Quant FinanceStanford FinMath - Careers in Quant Finance
Stanford FinMath - Careers in Quant Finance
 
Berkeley Financial Engineering - Guidance on Careers in Quantitative Finance
Berkeley Financial Engineering - Guidance on Careers in Quantitative FinanceBerkeley Financial Engineering - Guidance on Careers in Quantitative Finance
Berkeley Financial Engineering - Guidance on Careers in Quantitative Finance
 
Introduction to Stochastic calculus
Introduction to Stochastic calculusIntroduction to Stochastic calculus
Introduction to Stochastic calculus
 
Careers in Quant Finance - IIT Delhi
Careers in Quant Finance - IIT DelhiCareers in Quant Finance - IIT Delhi
Careers in Quant Finance - IIT Delhi
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in Dotty
 
Risk Pooling sensitivity to Correlation
Risk Pooling sensitivity to CorrelationRisk Pooling sensitivity to Correlation
Risk Pooling sensitivity to Correlation
 
Fitness 101 - Mumbai
Fitness 101 - MumbaiFitness 101 - Mumbai
Fitness 101 - Mumbai
 
HOW can India's Parliament function better?
HOW can India's Parliament function better?HOW can India's Parliament function better?
HOW can India's Parliament function better?
 
Zinnov zones - Digital in Retail
Zinnov zones - Digital in RetailZinnov zones - Digital in Retail
Zinnov zones - Digital in Retail
 

Similar to The Fuss about || Haskell | Scala | F# ||

Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Scott Wlaschin
 
app4.pptx
app4.pptxapp4.pptx
app4.pptxsg4795
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schoolsDan Bowen
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software DevelopmentNaveenkumar Muguda
 
Slides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MDSlides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MDSonaCharles2
 
Functional Programming - Past, Present and Future
Functional Programming - Past, Present and FutureFunctional Programming - Past, Present and Future
Functional Programming - Past, Present and FuturePushkar Kulkarni
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present FutureIndicThreads
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional ProgrammingYuan Wang
 
How to obtain and install R.ppt
How to obtain and install R.pptHow to obtain and install R.ppt
How to obtain and install R.pptrajalakshmi5921
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevJavaDayUA
 
Advanced Data Analytics with R Programming.ppt
Advanced Data Analytics with R Programming.pptAdvanced Data Analytics with R Programming.ppt
Advanced Data Analytics with R Programming.pptAnshika865276
 
Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in rubyKoen Handekyn
 
Porque aprender haskell me fez um programador python melhor?
Porque aprender haskell me fez um programador python melhor?Porque aprender haskell me fez um programador python melhor?
Porque aprender haskell me fez um programador python melhor?UFPA
 

Similar to The Fuss about || Haskell | Scala | F# || (20)

R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 
app4.pptx
app4.pptxapp4.pptx
app4.pptx
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schools
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software Development
 
17641.ppt
17641.ppt17641.ppt
17641.ppt
 
Slides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MDSlides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MD
 
17641.ppt
17641.ppt17641.ppt
17641.ppt
 
Functional Programming - Past, Present and Future
Functional Programming - Past, Present and FutureFunctional Programming - Past, Present and Future
Functional Programming - Past, Present and Future
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present Future
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Lexyacc
LexyaccLexyacc
Lexyacc
 
How to obtain and install R.ppt
How to obtain and install R.pptHow to obtain and install R.ppt
How to obtain and install R.ppt
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy Dyagilev
 
Advanced Data Analytics with R Programming.ppt
Advanced Data Analytics with R Programming.pptAdvanced Data Analytics with R Programming.ppt
Advanced Data Analytics with R Programming.ppt
 
Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in ruby
 
Porque aprender haskell me fez um programador python melhor?
Porque aprender haskell me fez um programador python melhor?Porque aprender haskell me fez um programador python melhor?
Porque aprender haskell me fez um programador python melhor?
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
 

More from Ashwin Rao

Stochastic Control/Reinforcement Learning for Optimal Market Making
Stochastic Control/Reinforcement Learning for Optimal Market MakingStochastic Control/Reinforcement Learning for Optimal Market Making
Stochastic Control/Reinforcement Learning for Optimal Market MakingAshwin Rao
 
Adaptive Multistage Sampling Algorithm: The Origins of Monte Carlo Tree Search
Adaptive Multistage Sampling Algorithm: The Origins of Monte Carlo Tree SearchAdaptive Multistage Sampling Algorithm: The Origins of Monte Carlo Tree Search
Adaptive Multistage Sampling Algorithm: The Origins of Monte Carlo Tree SearchAshwin Rao
 
Fundamental Theorems of Asset Pricing
Fundamental Theorems of Asset PricingFundamental Theorems of Asset Pricing
Fundamental Theorems of Asset PricingAshwin Rao
 
Evolutionary Strategies as an alternative to Reinforcement Learning
Evolutionary Strategies as an alternative to Reinforcement LearningEvolutionary Strategies as an alternative to Reinforcement Learning
Evolutionary Strategies as an alternative to Reinforcement LearningAshwin Rao
 
Principles of Mathematical Economics applied to a Physical-Stores Retail Busi...
Principles of Mathematical Economics applied to a Physical-Stores Retail Busi...Principles of Mathematical Economics applied to a Physical-Stores Retail Busi...
Principles of Mathematical Economics applied to a Physical-Stores Retail Busi...Ashwin Rao
 
Understanding Dynamic Programming through Bellman Operators
Understanding Dynamic Programming through Bellman OperatorsUnderstanding Dynamic Programming through Bellman Operators
Understanding Dynamic Programming through Bellman OperatorsAshwin Rao
 
Stochastic Control of Optimal Trade Order Execution
Stochastic Control of Optimal Trade Order ExecutionStochastic Control of Optimal Trade Order Execution
Stochastic Control of Optimal Trade Order ExecutionAshwin Rao
 
A.I. for Dynamic Decisioning under Uncertainty (for real-world problems in Re...
A.I. for Dynamic Decisioning under Uncertainty (for real-world problems in Re...A.I. for Dynamic Decisioning under Uncertainty (for real-world problems in Re...
A.I. for Dynamic Decisioning under Uncertainty (for real-world problems in Re...Ashwin Rao
 
Overview of Stochastic Calculus Foundations
Overview of Stochastic Calculus FoundationsOverview of Stochastic Calculus Foundations
Overview of Stochastic Calculus FoundationsAshwin Rao
 
Risk-Aversion, Risk-Premium and Utility Theory
Risk-Aversion, Risk-Premium and Utility TheoryRisk-Aversion, Risk-Premium and Utility Theory
Risk-Aversion, Risk-Premium and Utility TheoryAshwin Rao
 
Value Function Geometry and Gradient TD
Value Function Geometry and Gradient TDValue Function Geometry and Gradient TD
Value Function Geometry and Gradient TDAshwin Rao
 
Stanford CME 241 - Reinforcement Learning for Stochastic Control Problems in ...
Stanford CME 241 - Reinforcement Learning for Stochastic Control Problems in ...Stanford CME 241 - Reinforcement Learning for Stochastic Control Problems in ...
Stanford CME 241 - Reinforcement Learning for Stochastic Control Problems in ...Ashwin Rao
 
HJB Equation and Merton's Portfolio Problem
HJB Equation and Merton's Portfolio ProblemHJB Equation and Merton's Portfolio Problem
HJB Equation and Merton's Portfolio ProblemAshwin Rao
 
Policy Gradient Theorem
Policy Gradient TheoremPolicy Gradient Theorem
Policy Gradient TheoremAshwin Rao
 
A Quick and Terse Introduction to Efficient Frontier Mathematics
A Quick and Terse Introduction to Efficient Frontier MathematicsA Quick and Terse Introduction to Efficient Frontier Mathematics
A Quick and Terse Introduction to Efficient Frontier MathematicsAshwin Rao
 
Towards Improved Pricing and Hedging of Agency Mortgage-backed Securities
Towards Improved Pricing and Hedging of Agency Mortgage-backed SecuritiesTowards Improved Pricing and Hedging of Agency Mortgage-backed Securities
Towards Improved Pricing and Hedging of Agency Mortgage-backed SecuritiesAshwin Rao
 
Recursive Formulation of Gradient in a Dense Feed-Forward Deep Neural Network
Recursive Formulation of Gradient in a Dense Feed-Forward Deep Neural NetworkRecursive Formulation of Gradient in a Dense Feed-Forward Deep Neural Network
Recursive Formulation of Gradient in a Dense Feed-Forward Deep Neural NetworkAshwin Rao
 
Demystifying the Bias-Variance Tradeoff
Demystifying the Bias-Variance TradeoffDemystifying the Bias-Variance Tradeoff
Demystifying the Bias-Variance TradeoffAshwin Rao
 

More from Ashwin Rao (18)

Stochastic Control/Reinforcement Learning for Optimal Market Making
Stochastic Control/Reinforcement Learning for Optimal Market MakingStochastic Control/Reinforcement Learning for Optimal Market Making
Stochastic Control/Reinforcement Learning for Optimal Market Making
 
Adaptive Multistage Sampling Algorithm: The Origins of Monte Carlo Tree Search
Adaptive Multistage Sampling Algorithm: The Origins of Monte Carlo Tree SearchAdaptive Multistage Sampling Algorithm: The Origins of Monte Carlo Tree Search
Adaptive Multistage Sampling Algorithm: The Origins of Monte Carlo Tree Search
 
Fundamental Theorems of Asset Pricing
Fundamental Theorems of Asset PricingFundamental Theorems of Asset Pricing
Fundamental Theorems of Asset Pricing
 
Evolutionary Strategies as an alternative to Reinforcement Learning
Evolutionary Strategies as an alternative to Reinforcement LearningEvolutionary Strategies as an alternative to Reinforcement Learning
Evolutionary Strategies as an alternative to Reinforcement Learning
 
Principles of Mathematical Economics applied to a Physical-Stores Retail Busi...
Principles of Mathematical Economics applied to a Physical-Stores Retail Busi...Principles of Mathematical Economics applied to a Physical-Stores Retail Busi...
Principles of Mathematical Economics applied to a Physical-Stores Retail Busi...
 
Understanding Dynamic Programming through Bellman Operators
Understanding Dynamic Programming through Bellman OperatorsUnderstanding Dynamic Programming through Bellman Operators
Understanding Dynamic Programming through Bellman Operators
 
Stochastic Control of Optimal Trade Order Execution
Stochastic Control of Optimal Trade Order ExecutionStochastic Control of Optimal Trade Order Execution
Stochastic Control of Optimal Trade Order Execution
 
A.I. for Dynamic Decisioning under Uncertainty (for real-world problems in Re...
A.I. for Dynamic Decisioning under Uncertainty (for real-world problems in Re...A.I. for Dynamic Decisioning under Uncertainty (for real-world problems in Re...
A.I. for Dynamic Decisioning under Uncertainty (for real-world problems in Re...
 
Overview of Stochastic Calculus Foundations
Overview of Stochastic Calculus FoundationsOverview of Stochastic Calculus Foundations
Overview of Stochastic Calculus Foundations
 
Risk-Aversion, Risk-Premium and Utility Theory
Risk-Aversion, Risk-Premium and Utility TheoryRisk-Aversion, Risk-Premium and Utility Theory
Risk-Aversion, Risk-Premium and Utility Theory
 
Value Function Geometry and Gradient TD
Value Function Geometry and Gradient TDValue Function Geometry and Gradient TD
Value Function Geometry and Gradient TD
 
Stanford CME 241 - Reinforcement Learning for Stochastic Control Problems in ...
Stanford CME 241 - Reinforcement Learning for Stochastic Control Problems in ...Stanford CME 241 - Reinforcement Learning for Stochastic Control Problems in ...
Stanford CME 241 - Reinforcement Learning for Stochastic Control Problems in ...
 
HJB Equation and Merton's Portfolio Problem
HJB Equation and Merton's Portfolio ProblemHJB Equation and Merton's Portfolio Problem
HJB Equation and Merton's Portfolio Problem
 
Policy Gradient Theorem
Policy Gradient TheoremPolicy Gradient Theorem
Policy Gradient Theorem
 
A Quick and Terse Introduction to Efficient Frontier Mathematics
A Quick and Terse Introduction to Efficient Frontier MathematicsA Quick and Terse Introduction to Efficient Frontier Mathematics
A Quick and Terse Introduction to Efficient Frontier Mathematics
 
Towards Improved Pricing and Hedging of Agency Mortgage-backed Securities
Towards Improved Pricing and Hedging of Agency Mortgage-backed SecuritiesTowards Improved Pricing and Hedging of Agency Mortgage-backed Securities
Towards Improved Pricing and Hedging of Agency Mortgage-backed Securities
 
Recursive Formulation of Gradient in a Dense Feed-Forward Deep Neural Network
Recursive Formulation of Gradient in a Dense Feed-Forward Deep Neural NetworkRecursive Formulation of Gradient in a Dense Feed-Forward Deep Neural Network
Recursive Formulation of Gradient in a Dense Feed-Forward Deep Neural Network
 
Demystifying the Bias-Variance Tradeoff
Demystifying the Bias-Variance TradeoffDemystifying the Bias-Variance Tradeoff
Demystifying the Bias-Variance Tradeoff
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 

Recently uploaded (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 

The Fuss about || Haskell | Scala | F# ||

  • 1. Haskell, Scala, F# Are they worth the fuss?
  • 2. My Background • B.Tech. IIT-Bombay. Computer Science. • Ph.D. USC. Algorithmic Algebra. • VP. Goldman Sachs. Trading Strategist. • Managing Director. Morgan Stanley. • Founder & C.E.O. ZLemma (A Tech Startup).
  • 3. Haskell, Scala, F# • A different way of thinking about coding • Functional Programming is just one feature • High productivity (not easy to produce bugs) • Elegant and expressive (readable, maintainable) • Enjoyable and Addictive!
  • 4. A different way of thinking • The way we think when we do Math • It’s not about objects, state and “recipes” • It’s about (in Math-speak) sets, functions, compositions • Express what you want to do, not “how to do” • Elite programmers are influencing a cultural shift
  • 5. More than just FP • FP means stateless code & higher-order functions • {Haskell, Scala, F#} -> many other nice things • Static but Inferred Typing. Hence, safe yet succinct • Algebraic Data Types & Pattern Matching • The M word …
  • 6. Stateless code • Everything is a const. Banish the word “variable” • So: no loops, no reassignments, no object edits • Instead: map, fold, recursion, algebraic data types • Many small functions delegating to other functions • “State is the root cause of bugs” #MadeUpQuote
  • 7. def isprime(n): if n == 2: return True if n == 1 or n % 2 == 0: return False max = n**0.5+1 i = 3 while i <= max: if n % i == 0: return False i+=2 return 1 Python done badly
  • 8. def isPrime(n): if n == 1: return False else: return all(n % i != 0 for i in range(2, int(sqrt(n)) + 1) if isPrime(i)) Python done well But what about typing?
  • 9. let notFactorOf n =
 fun i -> n % i <> 0
 
 let intSqrt n =
 (int << sqrt << float) n
 
 let rec isPrime = function
 | 1 -> false
 | n -> Seq.forall (notFactorOf n) (seq {for i in 2 .. (intSqrt n) do if isPrime i then yield i})
 Same code in F#
  • 10. Higher-order Functions • Think of functions as a “generalization of data” • Functions accepting and/or returning function • Function composition (chaining) • Exploit the power of lambdas and currying • Laziness and memoization
  • 11. class NumSet(object): def __init__(self): self.__data__ = None def __calc__(self): return self def get_calc(self): if not self.__data__: self.__data__ = self.__calc__() return self.__data__ class NumSetLeaf(NumSet): def __init__(self, low, mid, high): super(NumSetLeaf, self).__init__() self.low = low self.mid = mid self.high = high self.triple = (self.low, self.mid, self.high) class NumSetOp(NumSet): def __init__(self, fl, args): super(NumSetOp, self).__init__() self.fl = fl self.args = args def __calc__(self): lows, mids, highs = zip(*[x.get_calc().triple for x in self.args]) fl = self.fl return NumSetLeaf(fl(lows), fl(mids), fl(highs)) class NumSetSum(NumSetOp): def __init__(self, args): super(NumSetSum, self).__init__(sum, args) 
 Can Python “Haskell”?
  • 12. class NumSetUnaryOp(NumSetOp): def __init__(self, f1, arg): super(NumSetUnaryOp, self).__init__(lambda l1, f1=f1: f1(*l1), [arg]) self.f1 = f1 self.arg = arg class NumSetScale(NumSetUnaryOp): def __init__(self, arg, k): super(NumSetScale, self).__init__(lambda x, k=k: x * k, arg) self.k = k class NumSetBinaryOp(NumSetOp): def __init__(self, f2, arg1, arg2): super(NumSetBinaryOp, self).__init__(lambda l2, f2=f2: f2(*l2), [arg1, arg2]) self.f2 = f2 self.arg1 = arg1 self.arg2 = arg2 class NumSetPlus(NumSetBinaryOp): def __init__(self, arg1, arg2): super(NumSetPlus, self).__init__(lambda x, y: x + y, arg1, arg2) class NumSetMult(NumSetBinaryOp): def __init__(self, arg1, arg2): super(NumSetMult, self).__init__(lambda x, y: x * y, arg1, arg2) l1 = NumSetLeaf(0.9, 0.92, 0.95 l2 = NumSetLeaf(0.8, 0.85, 0.9) l3 = NumSetLeaf(0.6, 0.7, 0.8) k = 0.6 l4 = NumSetPlus(NumSetScale(l1, k), NumSetScale(l2, 1.0 - k)) l5 = NumSetScale(NumSetSum([l4, l2, l3]), 0.3) Can Python “Haskell”?
  • 13. Infered Typing • The best of both worlds The rigor and safety of static typing Type inference lends syntactic lightness • Most coding errors are caught as one types code • Visualization of typing makes one think better • Scripting-style, rapid prototyping, REPL
  • 14. Algebraic Data Types • Elegant (recursive) way to express data structures • Makes writing of algorithms very easy and natural • Pattern-matching on edge cases and types • No more ugly/dangerous if-elseif, switch/case code • Type/structural safety. Hard to introduce bugs.
  • 15. type color = R | B type 'a tree = | E | T of color * 'a tree * 'a * 'a tree module Tree = let hd = function | E -> failwith "empty" | T(c, l, x, r) -> x let left = function | E -> failwith "empty" | T(c, l, x, r) -> l let right = function | E -> failwith "empty" | T(c, l, x, r) -> r let rec exists item = function | E -> false | T(c, l, x, r) -> if item = x then true elif item < x then exists item l else exists item r let balance = function (* Red nodes in relation to black root *) | B, T(R, T(R, a, x, b), y, c), z, d (* Left, left *) | B, T(R, a, x, T(R, b, y, c)), z, d (* Left, right *) | B, a, x, T(R, T(R, b, y, c), z, d) (* Right, left *) | B, a, x, T(R, b, y, T(R, c, z, d)) (* Right, right *) -> T(R, T(B, a, x, b), y, T(B, c, z, d)) | c, l, x, r -> T(c, l, x, r) let insert item tree = let rec ins = function | E -> T(R, E, item, E) | T(c, a, y, b) as node -> if item = y then node elif item < y then balance(c, ins a, y, b) else balance(c, a, y, ins b) match ins tree with | E -> failwith "Should never return empty from an insert" | T(_, l, x, r) -> T(B, l, x, r) Red-Black Tree in F#
  • 16. Make Data, Not Code • Data-driven coding (parametric algorithms) • Structured data framework controls your algorithms • A system where key logic is in data, not code • User wants a lot of control => Give him a DSL • Plug & Play system => Bring Your Own Data (DSL)
  • 17. DSL • Internal versus External • External: End-User DSL versus Dev DSL • Internal: Syntactic Sugar for clean, controlled code • Graphical representation of DSL => Functional • Well-typed, Functional DSL => Happy Algorithms!
  • 18. The M Word … • Monads - not just for “side-effects computing” • Functional way of doing imperative/sequential logic • Define Domains, Ranges, Compositions (Chains) • Sounds complex but yields clean, bug-free code • 4 types of X => M(X) monadic “Range Expansion” • g: A -> M(B), f: B -> M(C). How to get f o g: A -> M(C)
  • 19. 4 types of Monads • Failure: A -> Maybe(B), B -> Maybe(C). • Configurations: A -> Settings(B), B -> Settings(C). • Uncertainty: A -> Power(B), B -> Power(C). • Side-Effects: A -> IO(B), B -> IO(C) • Just figure out the bind and unit methods for each • Chain with bind and unit, and it’s all automatic!
  • 20. type Maybe<‘a> = | Just of 'a | Nothing let Return (x: 'a) : Maybe<'a> = Just(x) let Bind (mx: Maybe<'b>) (f: 'b -> Maybe<'c>) : Maybe<'c> = match mx with | Just(x) -> f x | Nothing -> Nothing Failure: “Maybe” monad Maybe(X) is an algebraic data type that can be X or “Error” g: A -> Maybe(B) f: B -> Maybe(C) How to produce f o g : A -> Maybe(C)
  • 21. let Return (x: 'a) : (‘s -> ‘a) = fun _ -> x let Bind (mx: ’s -> ‘b) (f: 'b -> (’s -> ‘c)) : (’s -> ‘c) = fun y -> f (mx y) y Configurations: “Settings” monad Settings(X) is a function from a “Settings” type to X g: A -> Settings(B) f: B -> Settings(C) How to produce f o g : A -> Settings(C)
  • 22. let Return (x: 'a) : Set<‘a> = set [x] let Bind (mx: Set<‘b>) (f: 'b -> Set<‘c>) : Set<‘c> = set [for x in mx do yield! f x] Uncertainty: “Power” monad Power(X) is the power set of X (the set of all subsets of X) g: A -> Power(B) f: B -> Power(C) How to produce f o g : A -> Power(C)
  • 23. let Return (x: 'a) : (unit -> ‘a) = fun () -> x let Bind (mx: unit -> ‘b) (f: 'b -> unit -> ‘c) : (unit -> ‘c) = f (mx()) Side-effects: “IO” monad IO(X) is a side-effects-function from Null (i.e., no args) to X g: A -> IO(B) f: B -> IO(C) How to produce f o g : A -> IO(C)