SlideShare a Scribd company logo
The Joy of
Functional Programming
   Jason Dew                Mark Gunnels                 John Long
jason@catamorphiclabs.com   mark@catamorphiclabs.com   john@catamorphiclabs.com
About Us

Catamorphic Labs strives to create more
value than it takes by applying open source
software, emerging technology, and data analysis
to complex issues confronting organizations.
Agenda


Theory: why are we interested in
functional programming languages?
Praxis: demonstration of interesting
characteristics of functional languages
Theory


There is an impedance mismatch
between hardware and software
Current software paradigms are too
complex to be reasoned about easily
Brooks’ Thesis


No technology in the near future will
yield an order-of-magnitude
improvement in software productivity
“accidental complexity” eliminated
Only “essential complexity” remained
Brooks was right



Twenty years later and no order-of-
 magnitude step has occurred in
      mainstream software.
But...



Thesis was correct, assumptions were not
Several studies indicate that functional
programming may provide this increase
Case Study

Ericsson’s “Four-fold Increase in
Productivity and Quality” paper
A ten-fold reduction in lines of code
when C++ code was rewritten in Erlang
Defect count fell in proportion to the
lines of code
The Cause?


Suggests Erlang was removing
“accidental complexity” by reducing
the presence of:
 Shared state
 Side-effects
Characteristics of
Functional Programming



 Side-effects are the exception, not the rule
 Shared state is avoided
 Variables are immutable
Praxis



Haskell
Erlang
Clojure
Haskell


A lazy, purely functional language
Difficult to master but very rewarding
to learn
One of the few good things designed by
a committee
Haskell



The type system
Non-strict evaluation
Pure functions
Basic Types

All of the regular types, Int, Double,
Char, String, etc.
Type synonyms
Makes your code more expressive
Algebraic Data Types



similar to an enumeration
define several values
instantiated with a “type constructor”
Integer Tree ADT
      Integer Tree




      2

             4
Integer Tree ADT




                my_tree

             Node




    Leaf 2           Node




             Empty          Leaf 4
Algebraic Data Types


More concise way to define data
structures
Automatically type check your data
types at compile time
Non-strict Evaluation


Also known as “lazy” evaluation
Function arguments are not computed
until required
Infinite data structures possible
Infinite Lists
Pure Functions


Functions with no side effects
The default in Haskell
Impure functions encapsulated inside
of the IO monad
Examples
Pure functions look normal




 Impure functions have type annotations
Erlang


Designed for scalability and reliability
Ericsson achieved 99.9999999% uptime
over the course of a year on a core router
Processes are very cheap in the Erlang VM
Erlang



Recursion
Pattern matching
Actor-based concurrency
Recursion


“To understand recursion, you must
understand recursion”
A function that calls itself
Tail call optimization
Recursion

Increases the call stack
May overflow
Recursion
Tail call optimization
Call stack remains constant in size
Pattern Matching



Simpler functions (less errors)
Abstract away logical branching (if,
switch, etc)
Simple Example
No Logic Branches
Complex Pattern Matching

  Match complex patterns or types
Complex Pattern Matching
Concurrency



Able to take advantage of multiple
processors across multiple machines
Actor based concurrency
Shared State Is Evil



Locking
Race conditions
Deadlock
Solution? No Shared State

   No locking needed, you don’t access the
   same memory
   Processes keep their own memory
   (copies of what they need)
   Changed something? Send a message.
Actor based Concurrency


  In Erlang, processes are the actors
  Each process has a mailbox
  Processes communicate via message
  passing
Actor based Concurrency

  Send a process a message with the !
  operator
  Processes run on any processor or
  computer
  Able to run millions of processes inside
  one virtual machine
Performance



Scales almost linearly with number of cores
Still being improved upon
Examples
Output
“hello!”
{message, today}
timeout
ok
Clojure



Lisp on the JVM
Embraces its Java roots
Clojure



Higher order functions
Pattern matching via multimethods
Concurrency and STM
Higher-order Functions



 Can take other functions as arguments
 Able to return functions as results
Higher-order Functions

     Take a function as an argument




 Applies a given function to a sequence of
elements and returns a sequence of results
Higher-order Functions
      Return a function
Currying, sortof
Pattern Matching



“Switch statements are a code smell.”
Multimethods


Clojure supports multimethods
Dispatching on types, values, attributes
and metadata of, and relationships
between, one or more arguments
Problem Statement
Define an “area” function for the shapes
Rectangle and Circle
Defining Multimethods

 Dispatching method must be supplied
 Will be applied to the arguments and
 produce a dispatch value
Defining Multimethods

Must create a new method of multimethod
    associated with a dispatch value
Defining Multimethods

        Voila... le multimethod




 Use of if, switch, etc. is eliminated by
          dispatching on type
Concurrency



Clojure has several concurrency mechanisms
The most interesting is...
Shared Transactional Memory (STM)
STM


Analogous to database transactions for
controlling access to shared memory
Works with refs, a mutable type for
synchronous, coordinated changes to
one or more values
Atomic. Consistent. Isolated.


    Updates are atomic
    If you update more than one ref in a
    transaction, the update appears as a
    simultaneous event to everything
    outside of the transaction
Atomic. Consistent. Isolated.


    Updates are consistent
    A new value can be checked with a
    validator function before allowing the
    transaction to commit
Atomic. Consistent. Isolated.



    Updates are isolated
    No transaction sees the effects of any
    other transaction while it is running
The Joy Of Functional Programming
Questions?

More Related Content

What's hot (20)

PPTX
DF15 - Dynamic Apex Binding with design patterns
Fronde Systems Group
 
ODP
The OCLforUML Profile
Edward Willink
 
PPTX
Insight into java 1.8, OOP VS FP
Syed Awais Mazhar Bukhari
 
PPTX
Stay fresh
Ahmed Mohamed
 
PPTX
XII Computer Science- Chapter 1-Function
Prem Joel
 
PDF
Object-oriented Analysis, Design & Programming
Allan Mangune
 
PDF
Domain specific languages and Scala
Filip Krikava
 
PDF
Introduction to c first week slides
luqman bawany
 
PPTX
Designing function families and bundles with java's behaviors parameterisatio...
Alain Lompo
 
PPTX
Unit testing and mocking in Python - PyCon 2018 - Kenya
Erick M'bwana
 
ODP
Aligning OCL and UML
Edward Willink
 
PDF
Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...
Dimitris Kolovos
 
PPTX
Gigabyte scale Amazon Product Reviews Sentiment Analysis Challenge: A scalabl...
ArunkumarAkkineni1
 
ODP
Embedded OCL Integration and Debugging
Edward Willink
 
ODP
At Last an OCL Debugger
Edward Willink
 
PPTX
Java 8 Functional Programming - I
Ugur Yeter
 
ODP
OCL Integration and Code Generation
Edward Willink
 
PPT
C#3.0 & Vb 9.0 New Features
techfreak
 
PPT
Lambdas
malliksunkara
 
PDF
How does intellisense work?
Adam Friedman
 
DF15 - Dynamic Apex Binding with design patterns
Fronde Systems Group
 
The OCLforUML Profile
Edward Willink
 
Insight into java 1.8, OOP VS FP
Syed Awais Mazhar Bukhari
 
Stay fresh
Ahmed Mohamed
 
XII Computer Science- Chapter 1-Function
Prem Joel
 
Object-oriented Analysis, Design & Programming
Allan Mangune
 
Domain specific languages and Scala
Filip Krikava
 
Introduction to c first week slides
luqman bawany
 
Designing function families and bundles with java's behaviors parameterisatio...
Alain Lompo
 
Unit testing and mocking in Python - PyCon 2018 - Kenya
Erick M'bwana
 
Aligning OCL and UML
Edward Willink
 
Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...
Dimitris Kolovos
 
Gigabyte scale Amazon Product Reviews Sentiment Analysis Challenge: A scalabl...
ArunkumarAkkineni1
 
Embedded OCL Integration and Debugging
Edward Willink
 
At Last an OCL Debugger
Edward Willink
 
Java 8 Functional Programming - I
Ugur Yeter
 
OCL Integration and Code Generation
Edward Willink
 
C#3.0 & Vb 9.0 New Features
techfreak
 
Lambdas
malliksunkara
 
How does intellisense work?
Adam Friedman
 

Viewers also liked (7)

PPTX
Uses of java
joeyparkker
 
PPTX
Delphi Parallel Programming Library
Mario Guedes
 
PPTX
Concurrency & Parallel Programming
Ramazan AYYILDIZ
 
PDF
Comparing different concurrency models on the JVM
Mario Fusco
 
PDF
Java 8 Stream API and RxJava Comparison
José Paumard
 
PPTX
Reactive Programming in Java 8 with Rx-Java
Kasun Indrasiri
 
PDF
Build Features, Not Apps
Natasha Murashev
 
Uses of java
joeyparkker
 
Delphi Parallel Programming Library
Mario Guedes
 
Concurrency & Parallel Programming
Ramazan AYYILDIZ
 
Comparing different concurrency models on the JVM
Mario Fusco
 
Java 8 Stream API and RxJava Comparison
José Paumard
 
Reactive Programming in Java 8 with Rx-Java
Kasun Indrasiri
 
Build Features, Not Apps
Natasha Murashev
 
Ad

Similar to The Joy Of Functional Programming (20)

PDF
I know Java, why should I consider Clojure?
sbjug
 
PPT
Clojure 1a
Krishna Chaytaniah
 
PDF
Introduction to Clojure
Renzo Borgatti
 
PPTX
Not Everything is an Object - Rocksolid Tour 2013
Gary Short
 
PDF
Clojure - An Introduction for Lisp Programmers
elliando dias
 
PDF
Clojure and The Robot Apocalypse
elliando dias
 
PDF
Functional programming with clojure
Lucy Fang
 
PDF
Functional programming
ijcd
 
KEY
LISP: How I Learned To Stop Worrying And Love Parantheses
Dominic Graefen
 
PDF
Introduction to clojure
Abbas Raza
 
KEY
Five Languages in a Moment
Sergio Gil
 
PPT
Indic threads pune12-polyglot & functional programming on jvm
IndicThreads
 
PDF
Functional Programming #FTW
Adriano Bonat
 
KEY
Scala: functional programming for the imperative mind
Sander Mak (@Sander_Mak)
 
PDF
Fun with Functional Programming in Clojure
Codemotion
 
PPTX
Fp and scala
vikram kadi
 
ODP
Clojure
alandipert
 
PDF
Clojure intro
Basav Nagur
 
PDF
Functional web with clojure
John Stevenson
 
PDF
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
I know Java, why should I consider Clojure?
sbjug
 
Introduction to Clojure
Renzo Borgatti
 
Not Everything is an Object - Rocksolid Tour 2013
Gary Short
 
Clojure - An Introduction for Lisp Programmers
elliando dias
 
Clojure and The Robot Apocalypse
elliando dias
 
Functional programming with clojure
Lucy Fang
 
Functional programming
ijcd
 
LISP: How I Learned To Stop Worrying And Love Parantheses
Dominic Graefen
 
Introduction to clojure
Abbas Raza
 
Five Languages in a Moment
Sergio Gil
 
Indic threads pune12-polyglot & functional programming on jvm
IndicThreads
 
Functional Programming #FTW
Adriano Bonat
 
Scala: functional programming for the imperative mind
Sander Mak (@Sander_Mak)
 
Fun with Functional Programming in Clojure
Codemotion
 
Fp and scala
vikram kadi
 
Clojure
alandipert
 
Clojure intro
Basav Nagur
 
Functional web with clojure
John Stevenson
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
Ad

Recently uploaded (20)

PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
PDF
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PDF
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Practical Applications of AI in Local Government
OnBoard
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
CapCut Pro PC Crack Latest Version Free Free
josanj305
 

The Joy Of Functional Programming