Your SlideShare is downloading. ×
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Introduction Functional Programming - Tech Hangout #11 - 2013.01.16


Published on

Functional Programming от Валеры Розувана …

Functional Programming от Валеры Розувана

* Tech Hangout – мероприятие, организованное разработчиками для разработчиков с целью обмена знаниями и опытом. Подобные встречи проводятся еженедельно по средам с 12:00 до 13:00 и охватывают исключительно инженерные темы. Формат данного ивента подразумевает под собой 30 минутный доклад на ранее определенную тему, и такую же по продолжительности дискуссию в формате круглого стола.
Если у вас есть неутомимое рвение к новым знаниям, профессиональному росту, или же вы хотите поделиться своим опытом - добро пожаловать в Hangout Club!

Присоединяйтесь к обсуждению -
Читайте нас на -

Published in: Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Introductory Functional Programming16.01.2013Valera Rozuvan
  • 2. We all know what programming is #include <stdio.h> int main(void) {   printf("Hello  world!n");   return 0; }
  • 3. Functional?A function is a rulewhich operates on aninput and produces anoutput.… programming ?
  • 4. Wait... isnt this #include <stdio.h> int main(void) {   printf("Hello world!n");   return 0; }already functional programming? It is after all a program that defines a function main(), which is then executed ...
  • 5. Wrong!
  • 6. In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. … just having functions isnt enough ...
  • 7. procedural FORTRAN, C, Pascal, BASIC imperative object-oriented C++, Java, C#, VB.NET, Pythonprogramming logic Gödel, PROLOG declarative functional Lisp, Clojure, Erlang, Haskell
  • 8. Imperative vs. Declarative● Imperative programming is a programming paradigm that describes computation in terms of statements that change a program state. Imperative programs define sequences of commands for the computer to perform.● Declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow.
  • 9. Huh?
  • 10. Example: factorialImperative: Declarative: def factorial(x) def factorial(x)   res = 1   if x < 2   while (x > 1)     return 1     res = res*x   else     x = x­1     return x*factorial(x­1)   end   end   return res end end print(factorial(10)) x = 10 print(factorial(x))
  • 11. Functional programming languages are declarative
  • 12. … in the beginning there was mathematics ...
  • 13. Lambda calculus● The λ-calculus calculus was introduced by mathematician Alonzo Church in the 1930s.● The λ-calculus treats functions "anonymously", without giving them explicit names.● In λ-calculus, functions are taken to be first class values, so functions may be used as the inputs and returned as outputs from other functions.● λ-calculus – a formal system for function definition, application, and recursion.
  • 14. Wow... … hard.
  • 15. Lambda calculus For Dummies
  • 16. Applying FP to the *real* world?● I am a JavaScript person, so I will write JS! you have been warned
  • 17. Can you do FP in JS?● If you define functional language as the language that supports first class functions and lambdas, then yes, JavaScript *is* a functional language.● JavaScript supports passing around functions as variables.● JavaScript supports anonymous functions. Short answer – yes! If you start to argue – no.
  • 18. A short demo● If you have any good taste at all, one ugly detail must be starting to bother you - the endlessly repeated for loop going over an array. function printArray(array) {   for (var i = 0; i < array.length; i++)     print(array[i]); }
  • 19. ● But what if we want to do something other than print? Because doing something is really a function, and functions are also values, we can pass our action as a function value. function forEach(array, action) {   for (var i = 0; i < array.length; i++)     action(array[i]); } forEach(   ["Wampeter", "Foma", "Granfalloon"],   print );
  • 20. ● And by making use of an anonymous function, something just like a for loop can be written with less useless details. function sum(numbers) {   var total = 0;   forEach(numbers, function (number) {     total += number;   });   return total; } show(sum[1, 10, 100]);
  • 21. ● On the whole, using more abstract (or higher level) constructs results in more information and less noise. Compare the following: var paragraphs = archive[today].split("n"); for (var i = 0; i < paragraphs.length; i++)     processParagraph(paragraphs[i]);versus forEach(   archive[today].split("n"),   ProcessParagraph );
  • 22. Use functional programmingfor the greater good!
  • 23. questions