SlideShare a Scribd company logo
1 of 16
Download to read offline
Functional Programming
  Chris Eidhof    Eelco Lempsink


    Amsterdam.rb, October 27, 2008



         ( tp
         , ui
          ) l
Functional programming in Ruby




(1..4).collect {|i| i*i }
 #=> [1, 4, 9, 16]

(1..10).inject {|sum, n| sum + n}
 #=> 55
Functional programming with Haskell



(1..4).collect {|i| i*i }


  map (λi → i ∗ i) [1 . . 4] -- [1,4,9,16]


(1..10).inject {|sum, n| sum + n}


  foldr (λn sum → sum + n) 0 [1 . . 10] -- 55
What is Haskell?




Haskell is a
  • strongly typed
  • lazy
  • purely functional
programming language
Everything is a function


• No “assignment”
• Referential transparancy
• Partial application, no parentheses needed


  a=5
  a=6     -- Invalid!



  squares xs = map (λx → x ∗ x) xs
Why should I learn Haskell?




• Functional Programming gives you a fresh way to look at
  problems
• Even if you don’t use a functional language
• Python, Ruby, C# all use ideas from FP
• Google’s Map/Reduce and Hadoop are large scale FP
Lists




data [a] = [ ]
         | a : [a]
Some standard functions



sum [ ]          =0
sum (x : xs)     = x + sum xs


product [ ]      =1
product (x : xs) = x ∗ product xs


and [ ]          = True
and (x : xs)     = x ∧ and xs
Everything is a fold!




foldr (⊕) e [ ]      =e
foldr (⊕) e (x : xs) = x ⊕ (foldr (⊕) e xs)



sum     = foldr ( + ) 0
product = foldr ( ∗ ) 1
and     = foldr ( ∧ ) True
Even map!




map f = foldr (λx tail → (f x) : tail) [ ]
Infinite lists...




primes         = sieve [2 . . ]
sieve (p : xs) = p : sieve [x | x ← xs
                                , x ‘mod‘ p ≡ 0
                           ]
QuickSort




qsort [ ]      = []
qsort (x : xs) = qsort (filter (<x) xs)
               + [x ]
               +
               + qsort (filter ( x) xs)
               +
What we didn’t tell you




• Function composition
• Types
• Purity and I/O
• Monads
• Foreign Function Interface
• ...
Haskell in the Real World




• Large applications (XMonad, Darcs, GHC, Yi)
• Lots of libraries (Today on hackage: 814 libraries and
  programs)
• Used by large companies (Credit Suisse, Galois, Microsoft,
  ABN Amro . . . )
• Lots of ways to learn Haskell ((free) textbooks, university
  courses, haskell wiki, blogs)
Functional programming




• ... sharpens your brain
• ... is lots of fun
• ... can help you become a better programmer
More information




• http://haskell.org
• http://hackage.haskell.org
• http://book.realworldhaskell.org/
• http://tupil.com

More Related Content

What's hot

Functional Programming, simplified
Functional Programming, simplifiedFunctional Programming, simplified
Functional Programming, simplifiedNaveenkumar Muguda
 
La R Users Group Survey Of R Graphics
La R Users Group Survey Of R GraphicsLa R Users Group Survey Of R Graphics
La R Users Group Survey Of R Graphicsguest43ed8709
 
Gopher conbr golang e data science - oficial
Gopher conbr   golang e data science - oficialGopher conbr   golang e data science - oficial
Gopher conbr golang e data science - oficialRodrigo Pinheiro
 
R - Basic Introduction
R - Basic IntroductionR - Basic Introduction
R - Basic IntroductionKU by ADDI
 
Haskell for Scala-ists
Haskell for Scala-istsHaskell for Scala-ists
Haskell for Scala-istschriseidhof
 
What Haskell taught us when we were not looking! - Eric Torreborre - Codemoti...
What Haskell taught us when we were not looking! - Eric Torreborre - Codemoti...What Haskell taught us when we were not looking! - Eric Torreborre - Codemoti...
What Haskell taught us when we were not looking! - Eric Torreborre - Codemoti...Codemotion
 
Coderstrust Presentation on C Language
Coderstrust Presentation on C LanguageCoderstrust Presentation on C Language
Coderstrust Presentation on C LanguageSrabon Sabbir
 
Visualization team presentation
Visualization team presentation Visualization team presentation
Visualization team presentation madhobilota
 
Rumus VB Menghitung Nilai Persamaan
Rumus VB Menghitung Nilai PersamaanRumus VB Menghitung Nilai Persamaan
Rumus VB Menghitung Nilai PersamaanT. Astari
 
Tools for research plotting
Tools for research plottingTools for research plotting
Tools for research plottingNimrita Koul
 
Javascript Libraries & Frameworks | Connor Goddard
Javascript Libraries & Frameworks | Connor GoddardJavascript Libraries & Frameworks | Connor Goddard
Javascript Libraries & Frameworks | Connor GoddardConnor Goddard
 
HelsinkiOS Jan 2015: Useful iOS Code Snippets
HelsinkiOS Jan 2015: Useful iOS Code SnippetsHelsinkiOS Jan 2015: Useful iOS Code Snippets
HelsinkiOS Jan 2015: Useful iOS Code SnippetsJouni Miettunen
 
Animaton Package in R An Example:
Animaton Package in R An Example:Animaton Package in R An Example:
Animaton Package in R An Example:Dr. Volkan OBAN
 

What's hot (19)

Functional Programming, simplified
Functional Programming, simplifiedFunctional Programming, simplified
Functional Programming, simplified
 
Cache and Drupal
Cache and DrupalCache and Drupal
Cache and Drupal
 
La R Users Group Survey Of R Graphics
La R Users Group Survey Of R GraphicsLa R Users Group Survey Of R Graphics
La R Users Group Survey Of R Graphics
 
Logging in JavaScript - Part-5
Logging in JavaScript - Part-5Logging in JavaScript - Part-5
Logging in JavaScript - Part-5
 
Gopher conbr golang e data science - oficial
Gopher conbr   golang e data science - oficialGopher conbr   golang e data science - oficial
Gopher conbr golang e data science - oficial
 
R - Basic Introduction
R - Basic IntroductionR - Basic Introduction
R - Basic Introduction
 
Haskell for Scala-ists
Haskell for Scala-istsHaskell for Scala-ists
Haskell for Scala-ists
 
What Haskell taught us when we were not looking! - Eric Torreborre - Codemoti...
What Haskell taught us when we were not looking! - Eric Torreborre - Codemoti...What Haskell taught us when we were not looking! - Eric Torreborre - Codemoti...
What Haskell taught us when we were not looking! - Eric Torreborre - Codemoti...
 
Coderstrust Presentation on C Language
Coderstrust Presentation on C LanguageCoderstrust Presentation on C Language
Coderstrust Presentation on C Language
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
Visualization team presentation
Visualization team presentation Visualization team presentation
Visualization team presentation
 
Rumus VB Menghitung Nilai Persamaan
Rumus VB Menghitung Nilai PersamaanRumus VB Menghitung Nilai Persamaan
Rumus VB Menghitung Nilai Persamaan
 
Tools for research plotting
Tools for research plottingTools for research plotting
Tools for research plotting
 
Javascript Libraries & Frameworks | Connor Goddard
Javascript Libraries & Frameworks | Connor GoddardJavascript Libraries & Frameworks | Connor Goddard
Javascript Libraries & Frameworks | Connor Goddard
 
HelsinkiOS Jan 2015: Useful iOS Code Snippets
HelsinkiOS Jan 2015: Useful iOS Code SnippetsHelsinkiOS Jan 2015: Useful iOS Code Snippets
HelsinkiOS Jan 2015: Useful iOS Code Snippets
 
C# 6.0
C# 6.0C# 6.0
C# 6.0
 
Python Set.pptx
Python Set.pptxPython Set.pptx
Python Set.pptx
 
Animaton Package in R An Example:
Animaton Package in R An Example:Animaton Package in R An Example:
Animaton Package in R An Example:
 
Python at 10.1
Python at 10.1Python at 10.1
Python at 10.1
 

Viewers also liked

Iglesia de San Nicolás. Un monumento árabe en Madrid
Iglesia de San Nicolás. Un monumento árabe en MadridIglesia de San Nicolás. Un monumento árabe en Madrid
Iglesia de San Nicolás. Un monumento árabe en MadridLa Gatera de la Villa
 
Reasonable RPC with Remotely
Reasonable RPC with RemotelyReasonable RPC with Remotely
Reasonable RPC with RemotelyTimothy Perrett
 
Web programming in Haskell
Web programming in HaskellWeb programming in Haskell
Web programming in Haskellchriseidhof
 
Compositional I/O Stream in Scala
Compositional I/O Stream in ScalaCompositional I/O Stream in Scala
Compositional I/O Stream in ScalaC4Media
 
Haskell for Scala-ists
Haskell for Scala-istsHaskell for Scala-ists
Haskell for Scala-istschriseidhof
 
Visualising Data on Interactive Maps
Visualising Data on Interactive MapsVisualising Data on Interactive Maps
Visualising Data on Interactive MapsAnna Pawlicka
 
Caching In The Cloud
Caching In The CloudCaching In The Cloud
Caching In The CloudAlex Miller
 
Groovy concurrency
Groovy concurrencyGroovy concurrency
Groovy concurrencyAlex Miller
 
Scaling Your Cache
Scaling Your CacheScaling Your Cache
Scaling Your CacheAlex Miller
 
Stream Execution with Clojure and Fork/join
Stream Execution with Clojure and Fork/joinStream Execution with Clojure and Fork/join
Stream Execution with Clojure and Fork/joinAlex Miller
 
Scaling Hibernate with Terracotta
Scaling Hibernate with TerracottaScaling Hibernate with Terracotta
Scaling Hibernate with TerracottaAlex Miller
 
Project Fortress
Project FortressProject Fortress
Project FortressAlex Miller
 
Cracking clojure
Cracking clojureCracking clojure
Cracking clojureAlex Miller
 
Purely Functional I/O
Purely Functional I/OPurely Functional I/O
Purely Functional I/OC4Media
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
Clojure: The Art of Abstraction
Clojure: The Art of AbstractionClojure: The Art of Abstraction
Clojure: The Art of AbstractionAlex Miller
 

Viewers also liked (20)

Iglesia de San Nicolás. Un monumento árabe en Madrid
Iglesia de San Nicolás. Un monumento árabe en MadridIglesia de San Nicolás. Un monumento árabe en Madrid
Iglesia de San Nicolás. Un monumento árabe en Madrid
 
Reasonable RPC with Remotely
Reasonable RPC with RemotelyReasonable RPC with Remotely
Reasonable RPC with Remotely
 
Web programming in Haskell
Web programming in HaskellWeb programming in Haskell
Web programming in Haskell
 
HN NL - Haskell
HN NL - HaskellHN NL - Haskell
HN NL - Haskell
 
Compositional I/O Stream in Scala
Compositional I/O Stream in ScalaCompositional I/O Stream in Scala
Compositional I/O Stream in Scala
 
Haskell for Scala-ists
Haskell for Scala-istsHaskell for Scala-ists
Haskell for Scala-ists
 
Visualising Data on Interactive Maps
Visualising Data on Interactive MapsVisualising Data on Interactive Maps
Visualising Data on Interactive Maps
 
Beyond Mere Actors
Beyond Mere ActorsBeyond Mere Actors
Beyond Mere Actors
 
Caching In The Cloud
Caching In The CloudCaching In The Cloud
Caching In The Cloud
 
Blogging ZOMG
Blogging ZOMGBlogging ZOMG
Blogging ZOMG
 
Groovy concurrency
Groovy concurrencyGroovy concurrency
Groovy concurrency
 
Cold Hard Cache
Cold Hard CacheCold Hard Cache
Cold Hard Cache
 
Scaling Your Cache
Scaling Your CacheScaling Your Cache
Scaling Your Cache
 
Stream Execution with Clojure and Fork/join
Stream Execution with Clojure and Fork/joinStream Execution with Clojure and Fork/join
Stream Execution with Clojure and Fork/join
 
Scaling Hibernate with Terracotta
Scaling Hibernate with TerracottaScaling Hibernate with Terracotta
Scaling Hibernate with Terracotta
 
Project Fortress
Project FortressProject Fortress
Project Fortress
 
Cracking clojure
Cracking clojureCracking clojure
Cracking clojure
 
Purely Functional I/O
Purely Functional I/OPurely Functional I/O
Purely Functional I/O
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
Clojure: The Art of Abstraction
Clojure: The Art of AbstractionClojure: The Art of Abstraction
Clojure: The Art of Abstraction
 

Similar to Functional Programming

Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a MomentSergio Gil
 
Haskell - Being lazy with class
Haskell - Being lazy with classHaskell - Being lazy with class
Haskell - Being lazy with classTiago Babo
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software DevelopmentNaveenkumar Muguda
 
Beauty and the beast - Haskell on JVM
Beauty and the beast  - Haskell on JVMBeauty and the beast  - Haskell on JVM
Beauty and the beast - Haskell on JVMJarek Ratajski
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Mattersromanandreg
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?osfameron
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and MonoidsHugo Gävert
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonAlex Payne
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospectivechenge2k
 
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014Ruslan Shevchenko
 
Introduction to Haskell: 2011-04-13
Introduction to Haskell: 2011-04-13Introduction to Haskell: 2011-04-13
Introduction to Haskell: 2011-04-13Jay Coskey
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Bryan O'Sullivan
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 
Introduction to meta-programming in scala
Introduction to meta-programming in scalaIntroduction to meta-programming in scala
Introduction to meta-programming in scalaAlessandro Marrella
 
From Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksFrom Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksSeniorDevOnly
 

Similar to Functional Programming (20)

Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
 
Haskell - Being lazy with class
Haskell - Being lazy with classHaskell - Being lazy with class
Haskell - Being lazy with class
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software Development
 
Beauty and the beast - Haskell on JVM
Beauty and the beast  - Haskell on JVMBeauty and the beast  - Haskell on JVM
Beauty and the beast - Haskell on JVM
 
Eta
EtaEta
Eta
 
Haskell
HaskellHaskell
Haskell
 
01. haskell introduction
01. haskell introduction01. haskell introduction
01. haskell introduction
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
 
04. haskell handling
04. haskell handling04. haskell handling
04. haskell handling
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
 
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014
 
Introduction to Haskell: 2011-04-13
Introduction to Haskell: 2011-04-13Introduction to Haskell: 2011-04-13
Introduction to Haskell: 2011-04-13
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Introduction to meta-programming in scala
Introduction to meta-programming in scalaIntroduction to meta-programming in scala
Introduction to meta-programming in scala
 
From Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksFrom Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risks
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
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
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
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
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
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...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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...
 

Functional Programming

  • 1. Functional Programming Chris Eidhof Eelco Lempsink Amsterdam.rb, October 27, 2008 ( tp , ui ) l
  • 2. Functional programming in Ruby (1..4).collect {|i| i*i } #=> [1, 4, 9, 16] (1..10).inject {|sum, n| sum + n} #=> 55
  • 3. Functional programming with Haskell (1..4).collect {|i| i*i } map (λi → i ∗ i) [1 . . 4] -- [1,4,9,16] (1..10).inject {|sum, n| sum + n} foldr (λn sum → sum + n) 0 [1 . . 10] -- 55
  • 4. What is Haskell? Haskell is a • strongly typed • lazy • purely functional programming language
  • 5. Everything is a function • No “assignment” • Referential transparancy • Partial application, no parentheses needed a=5 a=6 -- Invalid! squares xs = map (λx → x ∗ x) xs
  • 6. Why should I learn Haskell? • Functional Programming gives you a fresh way to look at problems • Even if you don’t use a functional language • Python, Ruby, C# all use ideas from FP • Google’s Map/Reduce and Hadoop are large scale FP
  • 7. Lists data [a] = [ ] | a : [a]
  • 8. Some standard functions sum [ ] =0 sum (x : xs) = x + sum xs product [ ] =1 product (x : xs) = x ∗ product xs and [ ] = True and (x : xs) = x ∧ and xs
  • 9. Everything is a fold! foldr (⊕) e [ ] =e foldr (⊕) e (x : xs) = x ⊕ (foldr (⊕) e xs) sum = foldr ( + ) 0 product = foldr ( ∗ ) 1 and = foldr ( ∧ ) True
  • 10. Even map! map f = foldr (λx tail → (f x) : tail) [ ]
  • 11. Infinite lists... primes = sieve [2 . . ] sieve (p : xs) = p : sieve [x | x ← xs , x ‘mod‘ p ≡ 0 ]
  • 12. QuickSort qsort [ ] = [] qsort (x : xs) = qsort (filter (<x) xs) + [x ] + + qsort (filter ( x) xs) +
  • 13. What we didn’t tell you • Function composition • Types • Purity and I/O • Monads • Foreign Function Interface • ...
  • 14. Haskell in the Real World • Large applications (XMonad, Darcs, GHC, Yi) • Lots of libraries (Today on hackage: 814 libraries and programs) • Used by large companies (Credit Suisse, Galois, Microsoft, ABN Amro . . . ) • Lots of ways to learn Haskell ((free) textbooks, university courses, haskell wiki, blogs)
  • 15. Functional programming • ... sharpens your brain • ... is lots of fun • ... can help you become a better programmer
  • 16. More information • http://haskell.org • http://hackage.haskell.org • http://book.realworldhaskell.org/ • http://tupil.com