Giancarlo Valente spiega il functional programming all'incontro mensile del Club degli Sviluppatori di Puglia. La storia da Alonzo Church e il lambda calcolo fino ai giorni d'oggi con la confluenza del functional programming nei linguaggi imperativi tradizionali. Esempi in Javascript, php, Erlang, haskell.
Il video del talk su youtube :)
https://youtu.be/LGIGyrD9Y9w
15. LA MIA FANTASIA INIZIO' A CORRERE IN UN PARADISO DI ELEGANZA
cartelle_esattoriali = [
elabora_cartella(contribuente)
for contribuente in contribuenti
if contribuente.valido
]
16. MENTRE OGNI GIORNO DOVEVO FARE QUESTO
Dim contribuenti(100) as Contribuente
Dim cartelle_esattoriali As New List(Of Cartella_Esattoriale)
Dim i ad Integer
For i = 1 To contribuenti.Length
contribuente = contribuenti[i]
if contribuente.valido then
cartelle_esattoriali.add(elabora_cartella(contribuente))
end if
Next
17. il python posso leggerlo
il vb devo eseguirlo
cartelle_esattoriali = [
elabora_cartella(contribuente)
for contribuente in contribuenti
if contribuente.valido
]
Dim contribuenti(100) as Contribuente
Dim cartelle_esattoriali As New List(Of Cartella_Esattoriale)
Dim i as Integer
For i = 1 To contribuenti.Length
contribuente = contribuenti[i]
if contribuente.valido then
cartelle_esattoriali.add(elabora_cartella(contribuente))
end if
Next
29. JAVASCRIPT E' UN'IMPLEMENTAZIONE DI SCHEME ????
"In 1995, the company recruited Brendan Eich with the goal of embedding the Scheme
programming language into its Netscape Navigator. "
wikipedia
40. QUALSIASI MACCHINA DI TURING
PUO' ESSERE ESPRESSA IN LAMBDA CALCOLO
Turing machines and lambda calculus are equivalent in power
in 1936 Turing proved that both models are equally strong in the sense
that they de ne the same class of computable functions
History of Computing at Princeton University
42. Based on the concept of a Turing machine are the present day Von Neumann computers.
Conceptually these are Turing machines with random access registers. Imperative programming
languages such as Fortran, Pascal etcetera as well as all the assembler languages are based on
the way a Turing machine is instructed: by a sequence of statements.
Functional programming languages, like Miranda, ML etcetera, are based on the lambda calculus.
An early (although somewhat hybrid) example of such a language is Lisp. Reduction machines are
speci cally designed for the execution of these functional languages.
fonte - lambda calcolo cs.kun.nl
57. FUNCTIONS
functions maps inputo to output
INPUT x
FUNCTION f:
OUTPUT f(x)
maps values between a domain and a codomain
Input and outputs values already exists
wikipedia - Function in mathematics
58. FUNCTIONS
f(x) = x + 1
1 ---> 2
6 ---> 7
9 ---> 10
un valore e' qualcosa che non cambia nel tempo
72. IMMUTABILITA'
i valori esistono ... le funzioni li mappano soltanto
lo stato non viene modi cato, ne' trasformato
una funzione viene valutata e ritorna un nuovo valore
EVALUATION
73. i dati vengono trattati come immutabili
immagina un mondo dove nessuno puo' rubare o modi care un
qualcosa ...
100. come farestin un ciclo di elaborazione in PHP ?
nooooo posso fare di meglio
risultati = []
for elemento in contenitore
risultati[] = elabora(elemento)
109. MAP, REDUCE, FILTER ETC ETC
oggi esistono diverse librerie per ogni linguaggio che facilitano l'adozione di uno stile di
programmaizone funzionale
JS, PHP, C#, C++
114. OOP SOLID PRINCIPLES
Single Responsability Principle Function
Open/closed Principle higher-order functions
Liskov Substitution Principle polimor smo parametrico
Interface Segregation Principle Function
Lev Gorodinski
128. MASSIVELY PARALLELIZABLE
il compilatore puo' analizzare il codice e capire che R1 e R3 possono essere calcolati in parallelo,
poi calcola R2, e quindi R4 e' pronto
R1 = faiQualcosa_1_QuiCon(A, B, C)
R2 = faiQualcosa_2_QuiCon(A, R1)
R3 = faiQualcosa_3_QuiCon(C, D)
R4 = faiQualcosa_4_QuiCon(R3, R2)
print R4
137. CAN PROGRAMMING BE LIBERATED FROM THE VON NEUMAN STYLE? A
FUNCTIONAL STYLE AND ITS ALGEBRA OF PROGRAMS
John Backus - 1977 Turing Award Lecture
Algebra of programs
140. DICHIARIATIVO
HASKELL TROVERA' MAI LA SUA NICCHIA ?
haskell dichiarativo ..
non ci hanno lavorato tante persone quante sul compilatore C
potra' fare come SQL ottimizzazioni anche basandosi sullestatistiche in esecuzione
https://www.quora.com/Is-
Haskell-as-fast-as-C++-If-not-why-not
143. FPGA sysntesys from a functional declartive language
http://www.clash-lang.org/
http://yager.io/HaSKI/HaSKI.html
http://christiaanb.github.io/posts/clash-fpga-starter/