SlideShare a Scribd company logo
Functional
Programming
Past, Present and Future
Pushkar N Kulkarni
IBM Runtimes
IBM India Software Lab
Functional Programming - today’s special
…
• Timeline – parallel to the imperative timeline
• Languages
• Concepts
Goal: Bootstrapping for functional programming
The beginning of all creation …
Theory of Computation <- Math + Logic
Alonzo Church
Lambda Calculus
Alan Turing
Turing Machine
Stephen Kleene
Recursive Function
Theory
Lambda Calculus
It’s a formal system in mathematical logic for
expressing computation based on function
abstraction and application using variable binding
and substitution.
~ Wikipedia
Lambda Calculus – Fundamental Idea
x //variable
t //lambda term
Λx.t //lambda abstraction
Λx. x2
+1 // x is bound in t by Λx
Λx. x2
+1(2) = 22
+1 = 5 //application
Note: A lambda abstraction has no name
LISP - 1958
LIST Processor
Influenced by Church’s
lambda calculus
notation
Multi-paradigm, pre-fix
notation
John McCarthy
LISP
;;Employee compensation
(defun total (bonus-calc base)
(+ (funcall bonus-calc base) base))
;; Good month
(total #'(lambda (x)(* 0.8 x)) 10000)
;; Bad month
(total #'(lambda (x)(+ (* 0.2 x) 10)) 10000)
LISP – Well known dialects
• Scheme – 1970
• Common Lisp – 1984
• Racket – 1984
• Clojure – 2007
• Lisp Flavoured Erlang (LFE) – 2008 (v1 March
2016)
Functional Programming - Past, Present and Future
Academic Research (1960 – 1985)
• ISWIM – If You See What I Mean – 1966
• SASL – St. Andrews Static Language – 1972
• ML – MetaLanguage – 1973 => Ocaml, F#
• Miranda – 1985 => Haskell
Back to some Lambda Calculus
F(x) = x3
+4x //F(x) id a first-order function
//maps values to values
dF(x)/dx = 3x2
+ 4
//d/dx maps functions to functions
d/dx is an example of higher-order functions
Higher-order Functions
A function is a higher-order function if:
• It takes at least one function as an argument OR
• It returns a function
All other functions are first–order functions!
Erlang - 1984
Designed for massive scalable soft real time
systems
Fault-tolerance and concurrency
Erlang
Multi-paradigm, but has a functional core
•First-class functions
Functions can be passed to functions
First-class citizens
=> Higher-order functions
•Immutable values
Immutable “variables” – creating new values instead
Minimizing moving parts has benefits
Erlang – Higher-order functions
%base salaries
S = [10000, 30000, 40000, 15000].
%The Bonus calculator
Bonus = fun(X)-> X + X*0.2 + 1500 end.
%Total salaries
T = lists:map(Bonus, S)
>> [13500, 37500, 49500, 19500]
Erlang – Higher-order functions
%find total salaries exceeding 30000
MoreThan30K = fun(Y) -> Y > 30000 end.
lists:filter(MoreThan30K,T).
>> [37500, 49500]
You just learnt “map” and “filter”. Let them sink in!
Haskell - 1990
• Full blown functional language
• Algebraic data types and type classes
• No statements – the entire program is an
”expression”
• Pattern matching
• Lazy evaluation
• Purely functional – functions have no side effect
Haskell – Algebraic Data Types (ADT)
• Derived from Type Theory
• A composite type - formed by combining other
types
data List a = Nil
| Cons a (List a)
data Tree a = Node a (Tree a) (Tree a)
| Nil
Haskell – Pattern Matching
-- construct a List from an list
makeList (x:xs) = Cons x (makeList xs)
makeList [] = Nil
-- construct an list from a List
makeArr (Cons x (xs)) = x:(makeArr xs)
makeArr Nil = []
Quiz
Why was the language named Haskell?
Haskell Curry (1900 – 1982)
Currying
Introduced by Shönfinkel
Lambda calculus deals with single argument
functions
What about multiple argument functions then?
If F(X, Y, Z) -> N, then
curry(F): X -> (Y -> (Z -> N))
Lambda Calculus - Currying
F(X, Y, Z) = X + Y + Z
F(1, 2, 3) = Fcurried(1)(2)(3)
//apply only one argument at a time
Fcurried (1) = F’curried
F’curried(2) = F”curried
F”curried(3) = 6
OCaml - 1996
• Multi-paradigm
• Derived from ML
• Static type system helps eliminate runtime
problems
• Emphasis on performance – good optimizing
compiler
Currying in OCaml
# let plus x y z = x + y + z;;
# plus 1 2 3;;
- : int = 6
# let x = plus 1;;
val x : int -> int -> int = <fun>
Currying in OCaml
# let y = x 2;;
val y : int -> int = <fun>
# y 3;;
- : int = 6
Cool, but what’s the use of all this?
Currying in OCaml
Function to add 2 to all numbers of a list
let add2 x = x + 2
List.map add2 [1;2;3;4;5];;
Function to add 3 to all numbers of a list
let add3 x = x + 3
List.map add3 [1;2;3;4;5];;
Currying in OCaml
With currying:
let add x y = x + y
List.map (add 2) [1;2;3;4;5]
List.map (add 3) [1;2;3;4;5]
•Better reuse of code
•Improved readability
Quiz
What significant event occurred around 1995
in the Programming Languages space?
Functional Programming on the JVM
(2004 – date)
• Groovy - 2003
• Scala - 2004
• Clojure - 2007
• Java 8 - 2014
Scala
• Seamless integration with
Java
• Combines object oriented
programming and functional
programming
• Type inference
• Higher order functions
• Pattern matchingMartin Odersky
Scala
Simple functional code to find the length of a list:
(no loops in functional programming!)
def listLength (list: List[_]): Int =
list match {
case Nil => 0
case _ => 1 + listLength(list.tail)
}
Any problems here?
Scala
listLength(List.Range(0, 100000))
>> StackOverflow
Are loops better than recursive calls then?
Has functional programming hit a barrier here?
Scala - TCO
No! You have tail recursion and tail-recursion
optimization (TCO)
def length(as: List[_]): Int = {
@tailrec
def length0(as: List[_], count: Int = 0): Int =
as match {
case Nil => count
case head :: tail => length0(tail, count+ 1)
}
length0(as)
}
Scala - TCO
Simplistic essence of tail-call optimization
Execution state
Single, reusable
stack frame
Clojure - 2007
Our fascination with LISP is never ending!
Rich Hickey
• LISP for the JVM
• Java-Clojure
interoperability
• Other implementations –
ClojureScript,
ClojureCLR
• Used in creative
computing!
Clojure
(defn fib[n]
(condp = n
0 1
1 1
(+ (fib (- n 1)) (fib (- n 2)))))
user=> (time (fib 40))
"Elapsed time: 2946.136757 msecs"
165580141
user=> (time (fib 40))
"Elapsed time: 2882.10746 msecs"
165580141
Clojure
Pure functions
•Referential Transparency
•No side effects – stateless programs
•Given an argument, the function must return the
same value! (fib 4) is always 3, for example.
=> Values (fib K) can be reused for all K
Speed up? Caching?
Clojure - Memoization
(def m-fib
(memoize (fn [n]
(condp = n
0 1
1 1
(+ (m-fib (- n 1)) (m-fib (- n 2)))))))
Clojure - Memoization
user=> (time (m-fib 40))
"Elapsed time: 0.823773 msecs"
165580141
user=> (time (m-fib 40))
"Elapsed time: 0.082013 msecs"
165580141
Java 8 - 2014
The exciting times begin!
•Lambdas
•Stream Interface – lazy evaluation!
•Functional Interfaces
•Default methods – for backward compatibility
A mammoth like Java embracing the functional
paradigm is a big cue about the times to come.
Lazy Evaluation
Laziness is not always bad
Lazy Evaluation
• Evaluate an expression only when it’s use is
encountered
• Values are created only when needed
• Reduction in memory footprint
• Fast
• In combination with memoization, results in very
efficient functional code
Problem
Find the number of first deliveries of overs, when a
batsman who scored at least five centuries and hit at
least 100 sixes, was out.
Java 8 – Lazy Evaluation
allDeliveries.stream()
.filter(d -> d.deliveryNumber() == 1)
.filter(d -> d.wicket())
.map(d -> d.getBatsman())
.filter(b -> b.totalCenturies() >= 5)
.filter(b -> b.totalSixes >= 100)
.count() //terminal operation
•Lambdas
•Immutability
•Lazy evaluation, terminal operation
•Map/filter
Java 8 - Parallelism
Parallel execution. Almost zero change to your code.
allDeliveries.parallelStream()
.filter(d -> d.deliveryNumber() == 1)
.filter(d -> d.wicket())
.map(d -> d.getBatsman())
.filter(b -> b.totalCenturies() >= 5)
.filter(b -> b.totalSixes >= 100)
.count() //terminal operation
Java 8
• No intentions of becoming a full blown functional
language
• Lambdas and lazy evaluation provide a big boost
• Readability improved – anonymous classes not
needed
• Reusability improved – lambdas, functional
interfaces
• Java 9 – better Stream interface expected
Idris – A peek into the future
• Data types are first class objects!
• You can generate data types, store them, pass
them around
• Dependent types were developed by Haskell
Curry to deepen the connection between
programming and logic (Curry-Howard
correspondence)
• Dependent types – types that depend on values!
• Influenced by Agda
Idris – dependent types
ListType : (singleton : Bool) -> Type
ListType False = List Nat
ListType True = Nat
sumList : (singleton : Bool)->ListType singleton->Nat
sumList False (x :: xs) = x + sumList False xs
sumList False [] = 0
sumList True x = x
Why Functional Programming
• Higher levels of behavioural abstraction – tell what
is to be done, not how to do it
• Agile Methodologies - Code reuse, readability
• Correctness
• Exploiting massively parallel hardware
Challenges
• Paradigm shift in thinking needed
• Newer design patterns – no imperative design
patterns
• Performance evaluation difficult – recursive data
structures, recursive functions
• Runtime performance – garbage collection critical
Recap
• Lambda Calculus
• Lambdas
• First-class functions, higher order functions
• Algebraic data types
• Pattern matching
• Currying
Recap
• Tail-call recursion and TCO
• Pure functions, referential transparency
• Memoization
• Lazy evaluation
• Parallelism
• Dependent data types
A programming language that does not change the way you
think is not worth knowing ~ Alan Perlis
Functional programming changes the way you think.
It’s worth knowing!
(Thank you!)
(twitter @pushkar_nk)
(github pushkarnk)
Ad

More Related Content

What's hot (20)

Introduction to Programming in LISP
Introduction to Programming in LISPIntroduction to Programming in LISP
Introduction to Programming in LISP
Knoldus Inc.
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
Denis
 
Functional Programming With Scala
Functional Programming With ScalaFunctional Programming With Scala
Functional Programming With Scala
Knoldus Inc.
 
Knolx session
Knolx sessionKnolx session
Knolx session
Knoldus Inc.
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
Jonas Bonér
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
Damian Jureczko
 
Java 8
Java 8Java 8
Java 8
vilniusjug
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
Typesafe
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
Tomer Gabel
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programming
Assaf Gannon
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
shinolajla
 
Lisp
LispLisp
Lisp
huzaifa ramzan
 
Scala: functional programming for the imperative mind
Scala: functional programming for the imperative mindScala: functional programming for the imperative mind
Scala: functional programming for the imperative mind
Sander Mak (@Sander_Mak)
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
Xebia IT Architects
 
20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas
shinolajla
 
Joy of scala
Joy of scalaJoy of scala
Joy of scala
Maxim Novak
 
Functional Programming in Scala: Notes
Functional Programming in Scala: NotesFunctional Programming in Scala: Notes
Functional Programming in Scala: Notes
Roberto Casadei
 
Aggregate Programming in Scala
Aggregate Programming in ScalaAggregate Programming in Scala
Aggregate Programming in Scala
Roberto Casadei
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
romanandreg
 
Introducing: A Complete Algebra of Data
Introducing: A Complete Algebra of DataIntroducing: A Complete Algebra of Data
Introducing: A Complete Algebra of Data
Inside Analysis
 
Introduction to Programming in LISP
Introduction to Programming in LISPIntroduction to Programming in LISP
Introduction to Programming in LISP
Knoldus Inc.
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
Denis
 
Functional Programming With Scala
Functional Programming With ScalaFunctional Programming With Scala
Functional Programming With Scala
Knoldus Inc.
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
Jonas Bonér
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
Damian Jureczko
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
Typesafe
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
Tomer Gabel
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programming
Assaf Gannon
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
shinolajla
 
Scala: functional programming for the imperative mind
Scala: functional programming for the imperative mindScala: functional programming for the imperative mind
Scala: functional programming for the imperative mind
Sander Mak (@Sander_Mak)
 
20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas
shinolajla
 
Functional Programming in Scala: Notes
Functional Programming in Scala: NotesFunctional Programming in Scala: Notes
Functional Programming in Scala: Notes
Roberto Casadei
 
Aggregate Programming in Scala
Aggregate Programming in ScalaAggregate Programming in Scala
Aggregate Programming in Scala
Roberto Casadei
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
romanandreg
 
Introducing: A Complete Algebra of Data
Introducing: A Complete Algebra of DataIntroducing: A Complete Algebra of Data
Introducing: A Complete Algebra of Data
Inside Analysis
 

Similar to Functional Programming - Past, Present and Future (20)

Clojure intro
Clojure introClojure intro
Clojure intro
Basav Nagur
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
Steve Zhang
 
Functional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smartFunctional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smart
Chen Fisher
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
nklmish
 
Functional programming with Scala
Functional programming with ScalaFunctional programming with Scala
Functional programming with Scala
Neelkanth Sachdeva
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
David Gu
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
Vinay Kumar
 
Functional Programming and Haskell - TWBR Away Day 2011
Functional Programming and Haskell - TWBR Away Day 2011Functional Programming and Haskell - TWBR Away Day 2011
Functional Programming and Haskell - TWBR Away Day 2011
Adriano Bonat
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
Albert Bifet
 
Lisp
LispLisp
Lisp
sonukumar142
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
GeeksLab Odessa
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture Two
Angelo Corsaro
 
Scala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian DragosScala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian Dragos
3Pillar Global
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
Luis Goldster
 
Functional Objects in Ruby: new horizons – Valentine Ostakh
Functional Objects in Ruby: new horizons  – Valentine OstakhFunctional Objects in Ruby: new horizons  – Valentine Ostakh
Functional Objects in Ruby: new horizons – Valentine Ostakh
Ruby Meditation
 
Python高级编程(二)
Python高级编程(二)Python高级编程(二)
Python高级编程(二)
Qiangning Hong
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
Steve Zhang
 
Functional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smartFunctional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smart
Chen Fisher
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
nklmish
 
Functional programming with Scala
Functional programming with ScalaFunctional programming with Scala
Functional programming with Scala
Neelkanth Sachdeva
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
David Gu
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
Vinay Kumar
 
Functional Programming and Haskell - TWBR Away Day 2011
Functional Programming and Haskell - TWBR Away Day 2011Functional Programming and Haskell - TWBR Away Day 2011
Functional Programming and Haskell - TWBR Away Day 2011
Adriano Bonat
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
Albert Bifet
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
GeeksLab Odessa
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture Two
Angelo Corsaro
 
Scala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian DragosScala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian Dragos
3Pillar Global
 
Functional Objects in Ruby: new horizons – Valentine Ostakh
Functional Objects in Ruby: new horizons  – Valentine OstakhFunctional Objects in Ruby: new horizons  – Valentine Ostakh
Functional Objects in Ruby: new horizons – Valentine Ostakh
Ruby Meditation
 
Python高级编程(二)
Python高级编程(二)Python高级编程(二)
Python高级编程(二)
Qiangning Hong
 
Ad

Recently uploaded (20)

LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Ad

Functional Programming - Past, Present and Future

  • 1. Functional Programming Past, Present and Future Pushkar N Kulkarni IBM Runtimes IBM India Software Lab
  • 2. Functional Programming - today’s special … • Timeline – parallel to the imperative timeline • Languages • Concepts Goal: Bootstrapping for functional programming
  • 3. The beginning of all creation …
  • 4. Theory of Computation <- Math + Logic Alonzo Church Lambda Calculus Alan Turing Turing Machine Stephen Kleene Recursive Function Theory
  • 5. Lambda Calculus It’s a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. ~ Wikipedia
  • 6. Lambda Calculus – Fundamental Idea x //variable t //lambda term Λx.t //lambda abstraction Λx. x2 +1 // x is bound in t by Λx Λx. x2 +1(2) = 22 +1 = 5 //application Note: A lambda abstraction has no name
  • 7. LISP - 1958 LIST Processor Influenced by Church’s lambda calculus notation Multi-paradigm, pre-fix notation John McCarthy
  • 8. LISP ;;Employee compensation (defun total (bonus-calc base) (+ (funcall bonus-calc base) base)) ;; Good month (total #'(lambda (x)(* 0.8 x)) 10000) ;; Bad month (total #'(lambda (x)(+ (* 0.2 x) 10)) 10000)
  • 9. LISP – Well known dialects • Scheme – 1970 • Common Lisp – 1984 • Racket – 1984 • Clojure – 2007 • Lisp Flavoured Erlang (LFE) – 2008 (v1 March 2016)
  • 11. Academic Research (1960 – 1985) • ISWIM – If You See What I Mean – 1966 • SASL – St. Andrews Static Language – 1972 • ML – MetaLanguage – 1973 => Ocaml, F# • Miranda – 1985 => Haskell
  • 12. Back to some Lambda Calculus F(x) = x3 +4x //F(x) id a first-order function //maps values to values dF(x)/dx = 3x2 + 4 //d/dx maps functions to functions d/dx is an example of higher-order functions
  • 13. Higher-order Functions A function is a higher-order function if: • It takes at least one function as an argument OR • It returns a function All other functions are first–order functions!
  • 14. Erlang - 1984 Designed for massive scalable soft real time systems Fault-tolerance and concurrency
  • 15. Erlang Multi-paradigm, but has a functional core •First-class functions Functions can be passed to functions First-class citizens => Higher-order functions •Immutable values Immutable “variables” – creating new values instead Minimizing moving parts has benefits
  • 16. Erlang – Higher-order functions %base salaries S = [10000, 30000, 40000, 15000]. %The Bonus calculator Bonus = fun(X)-> X + X*0.2 + 1500 end. %Total salaries T = lists:map(Bonus, S) >> [13500, 37500, 49500, 19500]
  • 17. Erlang – Higher-order functions %find total salaries exceeding 30000 MoreThan30K = fun(Y) -> Y > 30000 end. lists:filter(MoreThan30K,T). >> [37500, 49500] You just learnt “map” and “filter”. Let them sink in!
  • 18. Haskell - 1990 • Full blown functional language • Algebraic data types and type classes • No statements – the entire program is an ”expression” • Pattern matching • Lazy evaluation • Purely functional – functions have no side effect
  • 19. Haskell – Algebraic Data Types (ADT) • Derived from Type Theory • A composite type - formed by combining other types data List a = Nil | Cons a (List a) data Tree a = Node a (Tree a) (Tree a) | Nil
  • 20. Haskell – Pattern Matching -- construct a List from an list makeList (x:xs) = Cons x (makeList xs) makeList [] = Nil -- construct an list from a List makeArr (Cons x (xs)) = x:(makeArr xs) makeArr Nil = []
  • 21. Quiz Why was the language named Haskell?
  • 22. Haskell Curry (1900 – 1982)
  • 23. Currying Introduced by Shönfinkel Lambda calculus deals with single argument functions What about multiple argument functions then? If F(X, Y, Z) -> N, then curry(F): X -> (Y -> (Z -> N))
  • 24. Lambda Calculus - Currying F(X, Y, Z) = X + Y + Z F(1, 2, 3) = Fcurried(1)(2)(3) //apply only one argument at a time Fcurried (1) = F’curried F’curried(2) = F”curried F”curried(3) = 6
  • 25. OCaml - 1996 • Multi-paradigm • Derived from ML • Static type system helps eliminate runtime problems • Emphasis on performance – good optimizing compiler
  • 26. Currying in OCaml # let plus x y z = x + y + z;; # plus 1 2 3;; - : int = 6 # let x = plus 1;; val x : int -> int -> int = <fun>
  • 27. Currying in OCaml # let y = x 2;; val y : int -> int = <fun> # y 3;; - : int = 6 Cool, but what’s the use of all this?
  • 28. Currying in OCaml Function to add 2 to all numbers of a list let add2 x = x + 2 List.map add2 [1;2;3;4;5];; Function to add 3 to all numbers of a list let add3 x = x + 3 List.map add3 [1;2;3;4;5];;
  • 29. Currying in OCaml With currying: let add x y = x + y List.map (add 2) [1;2;3;4;5] List.map (add 3) [1;2;3;4;5] •Better reuse of code •Improved readability
  • 30. Quiz What significant event occurred around 1995 in the Programming Languages space?
  • 31. Functional Programming on the JVM (2004 – date) • Groovy - 2003 • Scala - 2004 • Clojure - 2007 • Java 8 - 2014
  • 32. Scala • Seamless integration with Java • Combines object oriented programming and functional programming • Type inference • Higher order functions • Pattern matchingMartin Odersky
  • 33. Scala Simple functional code to find the length of a list: (no loops in functional programming!) def listLength (list: List[_]): Int = list match { case Nil => 0 case _ => 1 + listLength(list.tail) } Any problems here?
  • 34. Scala listLength(List.Range(0, 100000)) >> StackOverflow Are loops better than recursive calls then? Has functional programming hit a barrier here?
  • 35. Scala - TCO No! You have tail recursion and tail-recursion optimization (TCO) def length(as: List[_]): Int = { @tailrec def length0(as: List[_], count: Int = 0): Int = as match { case Nil => count case head :: tail => length0(tail, count+ 1) } length0(as) }
  • 36. Scala - TCO Simplistic essence of tail-call optimization Execution state Single, reusable stack frame
  • 37. Clojure - 2007 Our fascination with LISP is never ending! Rich Hickey • LISP for the JVM • Java-Clojure interoperability • Other implementations – ClojureScript, ClojureCLR • Used in creative computing!
  • 38. Clojure (defn fib[n] (condp = n 0 1 1 1 (+ (fib (- n 1)) (fib (- n 2))))) user=> (time (fib 40)) "Elapsed time: 2946.136757 msecs" 165580141 user=> (time (fib 40)) "Elapsed time: 2882.10746 msecs" 165580141
  • 39. Clojure Pure functions •Referential Transparency •No side effects – stateless programs •Given an argument, the function must return the same value! (fib 4) is always 3, for example. => Values (fib K) can be reused for all K Speed up? Caching?
  • 40. Clojure - Memoization (def m-fib (memoize (fn [n] (condp = n 0 1 1 1 (+ (m-fib (- n 1)) (m-fib (- n 2)))))))
  • 41. Clojure - Memoization user=> (time (m-fib 40)) "Elapsed time: 0.823773 msecs" 165580141 user=> (time (m-fib 40)) "Elapsed time: 0.082013 msecs" 165580141
  • 42. Java 8 - 2014 The exciting times begin! •Lambdas •Stream Interface – lazy evaluation! •Functional Interfaces •Default methods – for backward compatibility A mammoth like Java embracing the functional paradigm is a big cue about the times to come.
  • 43. Lazy Evaluation Laziness is not always bad
  • 44. Lazy Evaluation • Evaluate an expression only when it’s use is encountered • Values are created only when needed • Reduction in memory footprint • Fast • In combination with memoization, results in very efficient functional code
  • 45. Problem Find the number of first deliveries of overs, when a batsman who scored at least five centuries and hit at least 100 sixes, was out.
  • 46. Java 8 – Lazy Evaluation allDeliveries.stream() .filter(d -> d.deliveryNumber() == 1) .filter(d -> d.wicket()) .map(d -> d.getBatsman()) .filter(b -> b.totalCenturies() >= 5) .filter(b -> b.totalSixes >= 100) .count() //terminal operation •Lambdas •Immutability •Lazy evaluation, terminal operation •Map/filter
  • 47. Java 8 - Parallelism Parallel execution. Almost zero change to your code. allDeliveries.parallelStream() .filter(d -> d.deliveryNumber() == 1) .filter(d -> d.wicket()) .map(d -> d.getBatsman()) .filter(b -> b.totalCenturies() >= 5) .filter(b -> b.totalSixes >= 100) .count() //terminal operation
  • 48. Java 8 • No intentions of becoming a full blown functional language • Lambdas and lazy evaluation provide a big boost • Readability improved – anonymous classes not needed • Reusability improved – lambdas, functional interfaces • Java 9 – better Stream interface expected
  • 49. Idris – A peek into the future • Data types are first class objects! • You can generate data types, store them, pass them around • Dependent types were developed by Haskell Curry to deepen the connection between programming and logic (Curry-Howard correspondence) • Dependent types – types that depend on values! • Influenced by Agda
  • 50. Idris – dependent types ListType : (singleton : Bool) -> Type ListType False = List Nat ListType True = Nat sumList : (singleton : Bool)->ListType singleton->Nat sumList False (x :: xs) = x + sumList False xs sumList False [] = 0 sumList True x = x
  • 51. Why Functional Programming • Higher levels of behavioural abstraction – tell what is to be done, not how to do it • Agile Methodologies - Code reuse, readability • Correctness • Exploiting massively parallel hardware
  • 52. Challenges • Paradigm shift in thinking needed • Newer design patterns – no imperative design patterns • Performance evaluation difficult – recursive data structures, recursive functions • Runtime performance – garbage collection critical
  • 53. Recap • Lambda Calculus • Lambdas • First-class functions, higher order functions • Algebraic data types • Pattern matching • Currying
  • 54. Recap • Tail-call recursion and TCO • Pure functions, referential transparency • Memoization • Lazy evaluation • Parallelism • Dependent data types
  • 55. A programming language that does not change the way you think is not worth knowing ~ Alan Perlis Functional programming changes the way you think. It’s worth knowing!