Hitchhiker's Guide to Functional Programming

15
Hitchhiker's Guide to Functional Programming

Transcript of Hitchhiker's Guide to Functional Programming

Significantly trivialized history of computing

Alonzo ChurchResearched decidability of algorithms and invented a

generic model of calculation – the λ-calculus (early 1930s*)

*see https://en.wikipedia.org/wiki/Lambda_calculus

Alan TuringCreated a model of a generic

computer – the Universal Turing machine (ca. 1936*)

*see https://en.wikipedia.org/wiki/Turing_machine

John von Neumann

Created the architecture of modern computers based on the Universal Turing machine (early 1940s*)

*see https://en.wikipedia.org/wiki/Von_Neumann_architecture

And PL features exploded...GOTO, mutation, pointers, null refs, exceptions, floating point numbers, inheritance, interfaces, threads…

See http://blog.ploeh.dk/2015/04/13/less-is-more-language-features/ for a discussion of harmful PL features

John McCarthyCreated Lisp language based on

the λ-calculus and featuring macros (ca. 1958*)

*see http://www-formal.stanford.edu/jmc/history/lisp/lisp.html

Edsger DijkstraMade a case against the

GOTO statement (in 1968*)*see https://en.wikipedia.org/wiki/Edsger_W._Dijkstra

A case against mutationIt’s about time to ban the next offender

What’s wrong with this code?

int sum = 0;

for (int i = 1; i <= 10; i++) {

if (i % 2 == 0) sum += i * i;}

System.out.println(sum);

Refactoring exercise

Erik Meijer

Recursion is GOTO of functional programming

● λ-Calculus is a model of computation● Program is data, generic evaluation algorithm

● Turing machine is a model of a computer

● Program is algorithm

Turing machine and λ-calculus are proven equivalent in terms of computability

Summary