SlideShare a Scribd company logo
Functional Programming
Ian Duggan
Styles of Programming
There are many styles of programming, depending on the
dimension you look at and the features available in the
language
● Imperative vs Functional
● Compiled vs Scripting
● Static vs Dynamic
● Implicit vs Explicit type conversion
● Managed vs Unmanaged (memory)
Programming Paradigms
Imperative - how to solve
● Procedural
● Object-oriented
Declarative - what to solve
● Functional
● Logic
The “Blub Paradox”
● Paul Graham, Beating the Averages
○ http://www.paulgraham.com/avg.html
● Imagine all languages on a line from the left to the
right
● Less powerful languages on the left, More powerful
languages on the right
● It is not possible to fully understand languages to the
right of the “best” language you know.
○ They have features difficult to grasp the usefulness of before you
use them (recursion, first-class functions, monads, actors macros,
etc…)
The “Blub Paradox”
Object-Oriented Programming
● Encapsulation by classes/objects
● Polymorphism through inheritance, etc.
● Mutable data (object state changes)
Functional vs Object-Oriented
● They are orthogonal concepts, not opposites
● Alan Kay, inventor of Smalltalk, said OO is about message
passing and isolation, not about objects, classes,
inheritance, etc.
● Erlang is the “most object-oriented language”
● http://bit.ly/1vFSqdk
Functional Programming
● Doesn’t have a precise definition
● Is more than a style of programming
○ I.e. you can do functional programming in any language,
it’s just that some languages push you toward this style
● Treat computation as evaluation of mathematical
functions
Functional Programming
● Often focuses on immutable data
● Data and Functions
● Declarative programming style
● Expressions (as opposed to statements)
Functional Programming
● Referential transparency
○ (same input, same output)
● Focus on eliminating “side effects”
● Has its origins in the “lambda calculus”
Lambda Calculus
● Formal system in mathematics for expressing
computation
● Developed by Alonzo Church in 1930s
● Based on abstraction and application using
binding and substitution
● Universal model of computation
Maxwell’s Equations
● Define electromagnetism
● Compact and precise
● Easy to work with
● “Cosmically spiritual” to a physicist
● God is in this
“Maxwell’s Equations” of Programming
● You can implement a LISP
from 7 basic primitives
● Hints at the “mathematical”
nature of functional
programming
● Strip away all the “junk” and
this is computation in its
“pure” form.
● Mentally relate this to
building a computer in Minecraft
● God is in this
First-Class Functions
● Functions are no different than data
● They can be
○ assigned to variables
○ passed as arguments
○ returned from functions
Higher-Order Functions
● Functions that operate on functions
● Take a function as input, return a new function as output
● The derivative, d/dx is a familiar example from math
Pure Functions
● Referentially transparent
● Have no side effects
● Memoization
● If value is not use, there is no effect in removing the
function
● Since they can’t affect each other, it is trivial to call
them in different orders or automatically parallelize
their application
Referential Transparency
● An expression is “referentially transparent” if it can be
replaced with its corresponding value.
● Substitution-model of computation
● Requires internals of computation to be “side effect
free”
○ No screen output
○ No setting of variables elsewhere
○ No writing to disk
○ No launching of missles
Recursion
● Looping is not a thing in functional languages
○ looping requires updating a loop value)
● Tail-call optimization
○ Return from function replaced with jump to beginning
● Continuation passing style
Tail-Call Optimization
● Makes infinite recursion not blow up
● Converts a recursive call to iteration
● Replaces call to function at “tail” into a “jmp” back to
the start of the function
Currying
● Translating a function that takes multiple arguments into
the composition of functions of one argument.
● Makes use of closures
Currying (in Javascript)
Partial Application
● Passing fewer than all of the arguments to a function
● Results in a function that is “partially applied”
● Can be used to call “half of a function”
Partial Application (Javascript)
Pattern Matching
● Like smart “case” statements in Ruby
● Compiler works to make statement “true” by binding LHS
values, as appropriate
● “Destructuring assignment” from javascript, but on
steroids
Pattern Matching (a tuple)
Pattern Matching (a list)
Piecewise Function Definition
● You may recall piecewise function definitions from math
● We can do this in many functional languages as well
Piecewise functions (with guards)
Immutable Data
● Once a value is set, it cannot be changed
● Makes it really easy to write durable code
○ You can be sure your values won’t change out from under you
● Makes concurrency stupidly-simple
○ Your values can’t change, so read away with abandon
Immutability : How do change state?
● Basically, you pass new state into a new function
● That function can be yourself
● Special values marked as mutable
○ Keep internal to a function or closure, and just be very careful when
you update (Clojure, Lisp, etc.)
● Monads (I won’t talk about these today)
○ Haskell
● Actor Model
○ Erlang/Elixir
Actor Model
An actor is a computational entity that, in response to a
message it receives, can concurrently:
● send a finite number of messages to other actors
● create a finite number of new actors
● designate the behavior to be used for the next message it
receives.
Actor Model
Each actor runs in it’s own thread
Actor Model
● An Actor has a mailbox
● Actors communicate with other Actors by sending them
immutable messages
● Messages are put into the Actor’s mailbox
Actor Model
● When an Actor’s mailbox has a message, code is run with
that message as an argument. This code is called
serially.
● When an Actor encounters an error, it dies.
○ “Let it crash”
● Actors can supervise other Actors, and if the supervised
Actors die, the supervisor is sent a message. If this
message isn’t handled, the supervisor dies.
OTP/Supervisors
● Actors watch other actors
● “Let it crash”
● Supervisor restarts
● Allows for “happy path programming”
Python
Javascript
F#
Haskell
Clojure
Erlang
Elixir
Elixir (also)
Using pure anonymous functions
Demo
Questions?

More Related Content

What's hot

Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
Shahriar Hyder
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
Muhammad Waqas
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
Md.Al-imran Roton
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
Ats Uiboupin
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
Moutaz Haddara
 
Programming paradigm
Programming paradigmProgramming paradigm
Programming paradigm
busyking03
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Iqra khalil
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
Jeff Fox
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
Forziatech
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
Alaref Abushaala
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languages
ppd1961
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
Tanmoy Barman
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java Ravi_Kant_Sahu
 
Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of java
vinay arora
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
ppd1961
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
Spotle.ai
 

What's hot (20)

Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
Programming paradigm
Programming paradigmProgramming paradigm
Programming paradigm
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languages
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java
 
Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of java
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
 

Similar to Functional programming

Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
datamantra
 
Introduction to functional programming, with Elixir
Introduction to functional programming,  with ElixirIntroduction to functional programming,  with Elixir
Introduction to functional programming, with Elixir
kirandanduprolu
 
Introduction to Functional programming
Introduction to Functional programmingIntroduction to Functional programming
Introduction to Functional programming
Ny Fanilo Andrianjafy, B.Eng.
 
GeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and AkkaGeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNightHyderabad
 
Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in RubyAlex Teut
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
SadhanaParameswaran
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
Konrad Szydlo
 
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Innovecs
 
Python functional programming
Python functional programmingPython functional programming
Python functional programming
Geison Goes
 
Ruby Functional Programming
Ruby Functional ProgrammingRuby Functional Programming
Ruby Functional Programming
Geison Goes
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_script
Vijay Kalyan
 
Reactive Software Systems
Reactive Software SystemsReactive Software Systems
Reactive Software Systems
Behrad Zari
 
Scala qq
Scala qqScala qq
Scala qq
羽祈 張
 
An introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptAn introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScript
TO THE NEW | Technology
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
Dhaval Dalal
 
Introduction of Object Oriented JavaScript
Introduction of Object Oriented JavaScriptIntroduction of Object Oriented JavaScript
Introduction of Object Oriented JavaScript
NexThoughts Technologies
 
Introduction to Erlang Programming Language
Introduction to Erlang Programming LanguageIntroduction to Erlang Programming Language
Introduction to Erlang Programming Language
Yasas Gunarathne
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?
sbjug
 
The Rise of Functional Programming
The Rise of Functional ProgrammingThe Rise of Functional Programming
The Rise of Functional Programming
Tjerk Wolterink
 

Similar to Functional programming (20)

Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
Introduction to functional programming, with Elixir
Introduction to functional programming,  with ElixirIntroduction to functional programming,  with Elixir
Introduction to functional programming, with Elixir
 
Introduction to Functional programming
Introduction to Functional programmingIntroduction to Functional programming
Introduction to Functional programming
 
GeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and AkkaGeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and Akka
 
Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in Ruby
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
 
Introductory func prog
Introductory func progIntroductory func prog
Introductory func prog
 
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
 
Python functional programming
Python functional programmingPython functional programming
Python functional programming
 
Ruby Functional Programming
Ruby Functional ProgrammingRuby Functional Programming
Ruby Functional Programming
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_script
 
Reactive Software Systems
Reactive Software SystemsReactive Software Systems
Reactive Software Systems
 
Scala qq
Scala qqScala qq
Scala qq
 
An introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptAn introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScript
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
 
Introduction of Object Oriented JavaScript
Introduction of Object Oriented JavaScriptIntroduction of Object Oriented JavaScript
Introduction of Object Oriented JavaScript
 
Introduction to Erlang Programming Language
Introduction to Erlang Programming LanguageIntroduction to Erlang Programming Language
Introduction to Erlang Programming Language
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?
 
The Rise of Functional Programming
The Rise of Functional ProgrammingThe Rise of Functional Programming
The Rise of Functional Programming
 

Recently uploaded

BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 

Recently uploaded (20)

BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 

Functional programming

  • 2. Styles of Programming There are many styles of programming, depending on the dimension you look at and the features available in the language ● Imperative vs Functional ● Compiled vs Scripting ● Static vs Dynamic ● Implicit vs Explicit type conversion ● Managed vs Unmanaged (memory)
  • 3. Programming Paradigms Imperative - how to solve ● Procedural ● Object-oriented Declarative - what to solve ● Functional ● Logic
  • 4. The “Blub Paradox” ● Paul Graham, Beating the Averages ○ http://www.paulgraham.com/avg.html ● Imagine all languages on a line from the left to the right ● Less powerful languages on the left, More powerful languages on the right ● It is not possible to fully understand languages to the right of the “best” language you know. ○ They have features difficult to grasp the usefulness of before you use them (recursion, first-class functions, monads, actors macros, etc…)
  • 6. Object-Oriented Programming ● Encapsulation by classes/objects ● Polymorphism through inheritance, etc. ● Mutable data (object state changes)
  • 7. Functional vs Object-Oriented ● They are orthogonal concepts, not opposites ● Alan Kay, inventor of Smalltalk, said OO is about message passing and isolation, not about objects, classes, inheritance, etc. ● Erlang is the “most object-oriented language” ● http://bit.ly/1vFSqdk
  • 8. Functional Programming ● Doesn’t have a precise definition ● Is more than a style of programming ○ I.e. you can do functional programming in any language, it’s just that some languages push you toward this style ● Treat computation as evaluation of mathematical functions
  • 9. Functional Programming ● Often focuses on immutable data ● Data and Functions ● Declarative programming style ● Expressions (as opposed to statements)
  • 10. Functional Programming ● Referential transparency ○ (same input, same output) ● Focus on eliminating “side effects” ● Has its origins in the “lambda calculus”
  • 11. Lambda Calculus ● Formal system in mathematics for expressing computation ● Developed by Alonzo Church in 1930s ● Based on abstraction and application using binding and substitution ● Universal model of computation
  • 12. Maxwell’s Equations ● Define electromagnetism ● Compact and precise ● Easy to work with ● “Cosmically spiritual” to a physicist ● God is in this
  • 13. “Maxwell’s Equations” of Programming ● You can implement a LISP from 7 basic primitives ● Hints at the “mathematical” nature of functional programming ● Strip away all the “junk” and this is computation in its “pure” form. ● Mentally relate this to building a computer in Minecraft ● God is in this
  • 14. First-Class Functions ● Functions are no different than data ● They can be ○ assigned to variables ○ passed as arguments ○ returned from functions
  • 15. Higher-Order Functions ● Functions that operate on functions ● Take a function as input, return a new function as output ● The derivative, d/dx is a familiar example from math
  • 16. Pure Functions ● Referentially transparent ● Have no side effects ● Memoization ● If value is not use, there is no effect in removing the function ● Since they can’t affect each other, it is trivial to call them in different orders or automatically parallelize their application
  • 17. Referential Transparency ● An expression is “referentially transparent” if it can be replaced with its corresponding value. ● Substitution-model of computation ● Requires internals of computation to be “side effect free” ○ No screen output ○ No setting of variables elsewhere ○ No writing to disk ○ No launching of missles
  • 18. Recursion ● Looping is not a thing in functional languages ○ looping requires updating a loop value) ● Tail-call optimization ○ Return from function replaced with jump to beginning ● Continuation passing style
  • 19. Tail-Call Optimization ● Makes infinite recursion not blow up ● Converts a recursive call to iteration ● Replaces call to function at “tail” into a “jmp” back to the start of the function
  • 20. Currying ● Translating a function that takes multiple arguments into the composition of functions of one argument. ● Makes use of closures
  • 22. Partial Application ● Passing fewer than all of the arguments to a function ● Results in a function that is “partially applied” ● Can be used to call “half of a function”
  • 24. Pattern Matching ● Like smart “case” statements in Ruby ● Compiler works to make statement “true” by binding LHS values, as appropriate ● “Destructuring assignment” from javascript, but on steroids
  • 27. Piecewise Function Definition ● You may recall piecewise function definitions from math ● We can do this in many functional languages as well
  • 29. Immutable Data ● Once a value is set, it cannot be changed ● Makes it really easy to write durable code ○ You can be sure your values won’t change out from under you ● Makes concurrency stupidly-simple ○ Your values can’t change, so read away with abandon
  • 30. Immutability : How do change state? ● Basically, you pass new state into a new function ● That function can be yourself ● Special values marked as mutable ○ Keep internal to a function or closure, and just be very careful when you update (Clojure, Lisp, etc.) ● Monads (I won’t talk about these today) ○ Haskell ● Actor Model ○ Erlang/Elixir
  • 31. Actor Model An actor is a computational entity that, in response to a message it receives, can concurrently: ● send a finite number of messages to other actors ● create a finite number of new actors ● designate the behavior to be used for the next message it receives.
  • 32. Actor Model Each actor runs in it’s own thread
  • 33. Actor Model ● An Actor has a mailbox ● Actors communicate with other Actors by sending them immutable messages ● Messages are put into the Actor’s mailbox
  • 34. Actor Model ● When an Actor’s mailbox has a message, code is run with that message as an argument. This code is called serially. ● When an Actor encounters an error, it dies. ○ “Let it crash” ● Actors can supervise other Actors, and if the supervised Actors die, the supervisor is sent a message. If this message isn’t handled, the supervisor dies.
  • 35. OTP/Supervisors ● Actors watch other actors ● “Let it crash” ● Supervisor restarts ● Allows for “happy path programming”
  • 38. F#
  • 43. Elixir (also) Using pure anonymous functions
  • 44. Demo