SlideShare uma empresa Scribd logo
1 de 99
var λ; Introduction to Functional Programming  with JavaScript (and a little Haskell) Will Kurt Will Kurt, Creative Commons Attribution-ShareAlike 3.0
"A language that doesn't effect how you think about programming is not worth learning" --Alan Perlis
So what is Functional Programming? http://www.flickr.com/photos/foundphotoslj/466713478/
What does this mean? ,[object Object]
No Side Effects! ,[object Object]
http://www.flickr.com/photos/23912576@N05/3056871500/
Haskell! http://www.flickr.com/photos/micurs/4870514382/
JavaScript!!! http://www.flickr.com/photos/jurvetson/96972777/
Rules for Today λ
Lists!!! ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Recursion! "If you already know what recursion is, just remember the answer. Otherwise, find someone who is standing closer to Douglas Hofstadter than you are; then ask him or her what recursion is." -- Andrew Plotkin
Exercise set 1a 10 minutes
Answers to set 1a
problem 1 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
problem 2 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
problem 2 continued... ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
problem 2 last one I swear (also very functional)... ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exercise set 1b 10 minutes
Answers to set 1b
problem 1 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
problem 2 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
problem 3 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
First class functions http://www.flickr.com/photos/richardmoross/2211308689/
First Class Functions (Haskell) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
First Class Functions (Haskell) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Lambda Functions ,[object Object]
Lambda Function (Haskell) ,[object Object],[object Object],[object Object]
Lambda Function (JavaScript) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exercise set 2 10 minutes
Answers to set 2
problem 1 ,[object Object],[object Object],[object Object]
problem 2 ,[object Object]
problem 3 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Break! 5 minutes
Closures ,[object Object]
Closures (Haskell) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exercise set 3 5 minutes
Answers to set 3
problem 1 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
problem 2 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
problem 3 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Higher Order Functions ,[object Object]
Map ,[object Object]
Map (Haskell) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Map (Haskell) ,[object Object],[object Object],[object Object]
Exercise set 4a 5 minutes
Answers to set 4a
problem 1 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
problem 2 ,[object Object],[object Object],[object Object]
Filter
Filter (Haskell) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exercise set 4b 10 minutes
Answers to set 4b
problem 1 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
problem 2 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Foldl (Reduce) http://en.wikipedia.org/wiki/File:Sermon_in_the_Deer_Park_depicted_at_Wat_Chedi_Liem-KayEss-1.jpeg
Foldl (Haskell) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Foldl (Haskell) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exercise set 4c 5 minutes
Answers to set 4c
problem 1 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
problem 2 ,[object Object],[object Object],[object Object]
Map (JavaScript) 'The Spolsky Map' function spolsky_map(fn, a)      {          for (i = 0; i < a.length; i++)          {              a[i] = fn(a[i]) ;          }      } note the side effects
The Spolsky Reduce (foldl) function spolsky_reduce(fn, a, init)      {          var s = init;          for (i = 0; i < a.length; i++)              s = fn( s, a[i] );          return s;      }
Break 5 minutes
Exercise 5a 5 minutes
Answers to set 5a
problem 1 ,[object Object]
problem 2 ,[object Object],[object Object],[object Object]
Standard Deviation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Standard Deviation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exercise 5b 10 minutes
Answers to set 5b
Standard Deviation (JavaScript) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Standard Deviation (JavaScript) ,[object Object],[object Object],[object Object],[object Object]
Standard Deviation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Function Currying
Currying (Haskell) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Currying (JavaScript) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Currying (JavaScript) purely functional ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Currying (JavaScript)  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exercise 6 10 minutes
Answers to set 6
problem 1 ,[object Object],[object Object]
problem 2 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Thanks! email: wckurt@gmail.com twitter: willkurt
Still have time? awesome!
Haskell vs JavaScript
Types!!! ,[object Object],[object Object],[object Object],[object Object]
Lazy Evaluation!!! ,[object Object],[object Object]
Pattern Matching ,[object Object],[object Object],[object Object],[object Object]
Pattern Matching ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Who actually uses this stuff? http://cufp.org/
Ocaml
 
 
more @ http://www.scala-lang.org/node/1658
Haskell
... continued more @ http://haskell.org/haskellwiki/Haskell_in_industry

Mais conteúdo relacionado

Mais procurados

Clojure: The Art of Abstraction
Clojure: The Art of AbstractionClojure: The Art of Abstraction
Clojure: The Art of AbstractionAlex Miller
 
Is java8 a true functional programming language
Is java8 a true functional programming languageIs java8 a true functional programming language
Is java8 a true functional programming languageSQLI
 
Is java8a truefunctionallanguage
Is java8a truefunctionallanguageIs java8a truefunctionallanguage
Is java8a truefunctionallanguageSamir Chekkal
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsBaruch Sadogursky
 
Java 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJava 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJason Swartz
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data ScienceMike Anderson
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to ImmutabilityKevlin Henney
 
JDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathJDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathDaniel Sawano
 
The Ring programming language version 1.6 book - Part 34 of 189
The Ring programming language version 1.6 book - Part 34 of 189The Ring programming language version 1.6 book - Part 34 of 189
The Ring programming language version 1.6 book - Part 34 of 189Mahmoud Samir Fayed
 
From Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn IntroductionFrom Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn Introductionelliando dias
 
Spotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathSpotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathDaniel Sawano
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldBTI360
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsEelco Visser
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Sciencehenrygarner
 

Mais procurados (20)

Clojure: The Art of Abstraction
Clojure: The Art of AbstractionClojure: The Art of Abstraction
Clojure: The Art of Abstraction
 
Is java8 a true functional programming language
Is java8 a true functional programming languageIs java8 a true functional programming language
Is java8 a true functional programming language
 
Is java8a truefunctionallanguage
Is java8a truefunctionallanguageIs java8a truefunctionallanguage
Is java8a truefunctionallanguage
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
V8
V8V8
V8
 
Monadologie
MonadologieMonadologie
Monadologie
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 Seasons
 
Clojure class
Clojure classClojure class
Clojure class
 
Java 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJava 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason Swartz
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to Immutability
 
JDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathJDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the Aftermath
 
The Ring programming language version 1.6 book - Part 34 of 189
The Ring programming language version 1.6 book - Part 34 of 189The Ring programming language version 1.6 book - Part 34 of 189
The Ring programming language version 1.6 book - Part 34 of 189
 
From Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn IntroductionFrom Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn Introduction
 
Spotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathSpotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the Aftermath
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
Advanced JavaScript
Advanced JavaScript Advanced JavaScript
Advanced JavaScript
 
Google Guava
Google GuavaGoogle Guava
Google Guava
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 

Semelhante a Intro to Functional Programming Workshop (code4lib)

Introduction to Functional Programming with Haskell and JavaScript
Introduction to Functional Programming with Haskell and JavaScriptIntroduction to Functional Programming with Haskell and JavaScript
Introduction to Functional Programming with Haskell and JavaScriptWill Kurt
 
The secrets of inverse brogramming
The secrets of inverse brogrammingThe secrets of inverse brogramming
The secrets of inverse brogrammingRichie Cotton
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)riue
 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskellujihisa
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programmingLukasz Dynowski
 
TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcionaltdc-globalcode
 
INTRODUCTION TO MATLAB session with notes
  INTRODUCTION TO MATLAB   session with  notes  INTRODUCTION TO MATLAB   session with  notes
INTRODUCTION TO MATLAB session with notesInfinity Tech Solutions
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basicsmsemenistyi
 
Transducers in JavaScript
Transducers in JavaScriptTransducers in JavaScript
Transducers in JavaScriptPavel Forkert
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?jonbodner
 
5.1 Quadratic Functions
5.1 Quadratic Functions5.1 Quadratic Functions
5.1 Quadratic Functionssmiller5
 
Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''OdessaJS Conf
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMDdhaval10690
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max PetruckMaksym Petruk
 

Semelhante a Intro to Functional Programming Workshop (code4lib) (20)

Introduction to Functional Programming with Haskell and JavaScript
Introduction to Functional Programming with Haskell and JavaScriptIntroduction to Functional Programming with Haskell and JavaScript
Introduction to Functional Programming with Haskell and JavaScript
 
The secrets of inverse brogramming
The secrets of inverse brogrammingThe secrets of inverse brogramming
The secrets of inverse brogramming
 
Millionways
MillionwaysMillionways
Millionways
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskell
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programming
 
PythonOOP
PythonOOPPythonOOP
PythonOOP
 
TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcional
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
INTRODUCTION TO MATLAB session with notes
  INTRODUCTION TO MATLAB   session with  notes  INTRODUCTION TO MATLAB   session with  notes
INTRODUCTION TO MATLAB session with notes
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
Mat lab day 1
Mat lab day 1Mat lab day 1
Mat lab day 1
 
Transducers in JavaScript
Transducers in JavaScriptTransducers in JavaScript
Transducers in JavaScript
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
 
5.1 Quadratic Functions
5.1 Quadratic Functions5.1 Quadratic Functions
5.1 Quadratic Functions
 
Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMD
 
gen math.pptx
gen math.pptxgen math.pptx
gen math.pptx
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max Petruck
 

Último

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Último (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Intro to Functional Programming Workshop (code4lib)

Notas do Editor

  1. Treats programming as the evaluation of mathematical processes Based on what&apos;s call the lambda calculus.  Mention this is turing complete way of representing a programing language with only anonymous function
  2. But what does this mean? Every function returns a value, that&apos;s what functions do they map one value to another. given an input a function always returns the same value in general it&apos;s more about stating what your problem is.
  3. The big this this all entails is there are no &apos;Side Effects&apos; in functional programming. When you call a function nothing about the world changes, can you say this is true about OOP?  This is much more meaningful that it may seem at first. If a variable is declared (and the usually aren&apos;t) it can never change it&apos;s value. This is even true for something like &apos;i&apos; in a &apos;for loop&apos; or the value a while loop checks... so that mean there are not classic iterators: no for loops, and no while loops.
  4. So why do all this? Number one reason by far for me is the really amazing abstractions you can come up with. For programming side effect free is an awesome guarantee There a lot of potential research that we can get some great and easy parallization from all this There are already functional features in languages like C#, python, ruby, LINQ. If you understand FP you can pick these things up a lot faster Big ideas are starting to come from the fp community.  When google release mapreduce, anyone with a background in lisp for functional programming would have instantly be able to guess roughly how the process worked.
  5. So I&apos;m going to talk about 2 languages tonight side by side. Haskell is an amazing language, but it has a reputation for being very difficult to learn.  As much as I would like to pretend that this is not the case, it really can be.  Tonight I&apos;m sticking to just a small subset of haskells expressiveness to go over the essentials of functional programming.  Get started with haskell isn&apos;t really so bad once you know the basics and understand fp a little better.
  6. Now JavaScript has the opposite problem. Most people view it as simply a mediocre clientside language. But it&apos;s actually an amazingly powerful language, and also probably the most functional of all mainstream languages. I want to show you that functional programming isn&apos;t really that hard, it&apos;s just different.  I&apos;m willing to bet that most anyone in the room has already used some really powerful functional features of javascript without even knowing it.
  7. Before we begin I want to just mentions lists a bit.  Functional programmin, with no standard loops, is very heavily based on recursion, and so it also relies heavily on lists. Here are some basic operations on a list that you&apos;ll need to be familiar with.  They go by many other names.
  8. The first essential feature of functional programming, is what is refered to as a &apos;first class function&apos; This is one of the easiest concepts to grasp, it seemly means that functions can be treated just like any other object, and most importantly that they can be passed just like arguments.
  9. so first we&apos;re going to put together a simple function this one adds &apos;2&apos; to a  number and this one addes &apos;3&apos; this are both in haskell and should be very simple to understand.  any questions
  10. Now we&apos;re going to make the opposite function, that is a function that takes a function and applies it to a predetermined argument. So arg is &apos;2&apos; takes whatever function you pass it and gives it the argument &apos;2&apos; &lt;walk them through the output&gt;
  11. How many of you have ever written any javascript at all? Everyone that just raised there hands has used a lambda function. All a lambda function is is an unnamed or anonymous function.  I&apos;ll show you in a bit how common these are in javascript Lambda functions are the core of funtional programming, although the can be all but removed from some languages. Initially what they offer may seem of limited use, but as we go on you should see how the become pretty essential. If you&apos;re insane you can literarly usual solely lambda functions to do all of your computation, you can even implment addition and subtraction without numbers.  Hell you can even implment recursion in using only unnamed functions.
  12. Now these examples are stupidly simple, but you&apos;ll see lambda popping up all over this presentaiton in various forms. so here we&apos;re defining a function, add4, as a lambda &lt;walk through notation? Now also notice how we can pass this function as a first class function directly to our previous argIsX function
  13. Here some everyday javascript, these snippets are just pulled straight from standard javascript tutorials.  You&apos;ve probably written code like this if you&apos;ve ever done any javascript.
  14. Closures sound more complicated then they are.  Closures let us capture some variable in the scope of a function we return... Examples will do you much better than me describing it.
  15. So here&apos;s add5 for reference. Now this pattern of addX is pretty obvious, there must be a way to abstract this away right? so we can make this functioncalled makeAdder that takes a values. here is the same code 2 different ways, in put cases we&apos;re returning a function that has this value we based enclosed in it. Now we can make adders more easily. So you can see in the about put the function we returned remembers what value we passed to it. This also demonstrates another important property of lambda functions.
  16. okay so proper first class functions, lambdas and closure are the core of functional programming.  coupled with recursion you&apos;re pretty much done. However these are really just the primative of functional programming.  Next we&apos;re going to answer what&apos;s probably the biggest question you have.  Since we throw out all the iterators I know of, how the hell do I get any actual work done? That brings us to higher order functions, by definiton these are just functions that take functions as an argument, but there are some that form the basis of how you should think about problems in fp.
  17. Map is the most obvious, it solve the problem of the vast majority of iteration that you do.   map takes a function and a list and returns a new list with that function applied to every item in it. From here on out I&apos;m going to show you how higher order functions work in haskell, and how there implemented in javascript
  18. this is actually a pretty easy concept. so in the first example double all takes a list, and the applys times 2 to each item, so it doubles every item in the list. square all does the same thing but squares them square and add just shows off how we can use our lambda again and upperCase takes a string an applies toUpper to each letter in that string, a string is afterall just a list of characters.
  19. just a note on haskell here, you can actually leave out the arguments on both sides if we&apos;re missing an arguement we essentially create a closure waiting for that argument. We&apos;ll talk more about this later.
  20. filter does what the name sounds like, it takes a function which performs a test and only returns values that pass.
  21. so this first case selects every item that is even the next selects every one that is evenly divisible by 17  And this last is a little different.  This is a neat trick called function composition.  what we do is apply the rightmost function and then send it&apos;s value to the left most.  this makes it very easy to define complicated functions by composing them. explain output
  22. Folds are very poweful, but also the most likely to give you a headache until you undertand them.  There are actually several types of folds, we&apos;re going to focus on what&apos;s call a left fold, foldl or often reduce (in ruby it&apos;s called inject). fold takes a function, and initial value, and a list of values and &apos;folds&apos; all the values of that list into a single value.
  23. The simpliest and most obious use of fold it to some values ina list, see here our function is &apos;add&apos; and our intial value is 0. This reverse is actually a bit more tricky, I&apos;ll actually walk you through this. finally I&apos;ll show you some more function composition. we can define sumOfSquare 2 ways, the first more verbose maps square to a list, and the folds it just like sum, The second composes our sum and squareAll functions.
  24. here I&apos;ll walk you through the recursion for the fold revers.
  25. Many of you may know of Joel Spolsky, he&apos;s one of the people behind stack over flow A few years ago he wrote about the functional properties of javascript and gave this as his implementation of map. But we can see here that this implementation itself is not functional.  In some cases this is meaningless, but notice what happens to the array we&apos;re passing?   In a purely functional work the original array will ALWAYS be untouched, in this case the original array is deleted.
  26. Once again Spolsky also implemented this, but once again it&apos;s not functional. However this time it is less damaging and probably more effiience.  Some languages let you choose when you want to be functional, choose wisely.
  27. Finally we&apos;ll discuss function currying. what happens in any language you know when you call a function that takes 3 arguements with only 2 arguement? Error right?  Well not in haskell, in haskell you get a new function waiting for the 3rd arguement. let&apos;s look at some examples
  28. here I&apos;ll defiine a new version of add that takes 2 arguments If I call it with only one then I get a function waiting for the next argument, you can see this is even easier than our earlier example that build closures
  29. what&apos;s crazy is that you can actually implement this functionality in javascript