This is a presentation I gave at Rotterdam University of Applied Science for first year students of computer science. The goal of this presentation was to introduce the students to functional programming and its principles.
2007 2003 2005 Alonzo Church develops the lambda calculus John McCarthy develops Lisp Peter Landin develops ISWIM, first pure functional language John Backus develops FP Robin Milner develops ML David Turner develops a number of lazy functional languages Development of Haskell is initiated, a standard pure functional language First release of Scala, designed by Martin Odersky First version of F#, developed by the F# Software Foundation and Microsoft Rich Hickey releases Clojure
are created. Why? Mutable values makes multithreaded programming difficult. Synchronization is required if multiple threads modify the same value. Immutable values remove the need of synchronization as concurrent reading is safe.
other piece of data. They can be passed as arguments to other functions or be returned as a result of a function. Why? Fosters code modularity and reusability which results in a smaller codebase.
the same arguments always yields the same result (referential transparency) and has no side effects. Why? Easier to design, test and understand. Allows the compiler to perform optimisations. Improves performance by making lazy evaluation possible.
* 2 ! scala> def sum(f: Int => Int, x: Int, y: Int) = f(x) + f(y) scala> sum(multiplyByTwo, 5, 4) res1: Int = 18 ! int multiplyByTwo(int x) { return x * 2 } ! int sum(int x, int y) { return x + y } sum(multiplyByTwo(5), multiplyByTwo(4)) Higher-order function With no higher-order function Sum is a higher-order function!
more variables which were not passed as arguments to the function and are defined in its enclosing scope. Why? Useful for callbacks in event-driven programming.
else xs.head + sum(xs.tail) } ! int []numbers = {1, 2, 3, 4, 5}; int total = 0; for(int i = 0; i < numbers.length; i++){ total = total + numbers[i]; } Recursion Iteration Sum calls itself!
which emphasises programming with pure functions and immutable data. A programming paradigm which models computations as evaluation of mathematical functions while avoiding mutable state.
or Clojure and start having fun in the REPL Google Erik Meijer’s Functional Programming Fundamentals lectures Enroll for Functional Programming Principles in Scala on Coursera