porque aprender haskell me fez um programador python melhor?
TRANSCRIPT
Porque aprender haskell me fez um programador
python melhor?
Baseado em fatos reais
Gustavo Pinto
2004 - belém, grad, php, sh2006 - amazontic, java, xp2008 - curitiba, msc, python2009 - aprioriti, xp, scrum2011 - recife, phd, haskell2012 - entropie, lean, scala
Belém
Belém
Belém
Belém
Belém
Belém
DISCLAIMER
Não tem código
Não tem código¬¬''
Mentira, tem mas épouquinho :-)
1912 ~ 1954
1912 ~ 19541936
1912 ~ 19541936
ON COMPUTABLE NUMBERS, WITH AN APPLICATION
TO THE ENTSCHEIDUNGS
PROBLEM
ON COMPUTABLE NUMBERS, WITH AN APPLICATION
TO THE ENTSCHEIDUNGS
PROBLEM
ON COMPUTABLE NUMBERS, WITH AN APPLICATION
TO THE DECISION PROBLEM
1903 ~1995
1903 ~19951936
1903 ~19951936
AN UNSOLVABLE PROBLEM OF ELEMENTARY
NUMBER THEORY
1936
1936
Church-Turing thesis
Church-Turing thesis
Church-Turing thesis
Equivalentes
Algumas features:
● Pure functions● Functions as first-class objects● No side effects
Algumas features:
● Pure functions● Functions as first-class objects● No side effects
Concurrency Friendly
Great.. But, what about Python??
Python functional
Is python functional?
Is python functional?
I have never considered Python to be heavily influenced by functional
languages, no matter what people say or think. I was much more familiar with imperative languages such as C and
Algol 68 and although I had made functions first-class objects, I didn't view
Python as a functional programming language. However, earlier on, it was
clear that users wanted to do much more with lists and functions.
http://python-history.blogspot.com.br/2009/04/origins-of-pythons-functional-features.html
I have never considered Python to be heavily influenced by functional
languages, no matter what people say or think. I was much more familiar with imperative languages such as C and
Algol 68 and although I had made functions first-class objects, I didn't view
Python as a functional programming language. However, earlier on, it was
clear that users wanted to do much more with lists and functions.
http://python-history.blogspot.com.br/2009/04/origins-of-pythons-functional-features.html
I have never considered Python to be heavily influenced by functional
languages, no matter what people say or think. I was much more familiar with imperative languages such as C and
Algol 68 and although I had made functions first-class objects, I didn't view
Python as a functional programming language. However, earlier on, it was
clear that users wanted to do much more with lists and functions.
http://python-history.blogspot.com.br/2009/04/origins-of-pythons-functional-features.html
I have never considered Python to be heavily influenced by functional
languages, no matter what people say or think. I was much more familiar with imperative languages such as C and
Algol 68 and although I had made functions first-class objects, I didn't view
Python as a functional programming language. However, earlier on, it was
clear that users wanted to do much more with lists and functions.
http://python-history.blogspot.com.br/2009/04/origins-of-pythons-functional-features.html
I see list and functions
hack, hack
if god exists: atepassar**2
search_list = lambda l,e : [ [ idx for idx, element in enumerate(l) if element ==
element_f ] for element_f in e]
search_list = lambda l,e : [ [ idx for idx, element in enumerate(l) if element ==
element_f ] for element_f in e]
List comprehensionA basic comprehension for a set that contains the first ten even natural numbers is
The part before the pipe is called the output function, x is the variable, N is the input set and x <= 10 is the predicate. That means that the set contains the doubles of all natural numbers that satisfy the predicate.
http://learnyouahaskell.com/starting-out#im-a-list-comprehension
List comprehensionA basic comprehension for a set that contains the first ten even natural numbers is
The part before the pipe is called the output function, x is the variable, N is the input set and x <= 10 is the predicate. That means that the set contains the doubles of all natural numbers that satisfy the predicate.
http://learnyouahaskell.com/starting-out#im-a-list-comprehension
List comprehensionA basic comprehension for a set that contains the first ten even natural numbers is
>>> [i for x in range (0, 100) if x > 10]
http://learnyouahaskell.com/starting-out#im-a-list-comprehension
List comprehensionA basic comprehension for a set that contains the first ten even natural numbers is
>>> [i for x in range (0, 100) if x > 10]>>> [[row[i] for row in matrix] for i in range(4)]
http://learnyouahaskell.com/starting-out#im-a-list-comprehension
List comprehensionA basic comprehension for a set that contains the first ten even natural numbers is
>>> [i for x in range (0, 100) if x > 10]>>> [[row[i] for row in matrix] for i in range(4)]>>> dict([(i, chr(65+i)) for i in range(4)])
http://learnyouahaskell.com/starting-out#im-a-list-comprehension
List comprehensionA basic comprehension for a set that contains the first ten even natural numbers is
>>> [i for x in range (0, 100) if x > 10]>>> [[row[i] for row in matrix] for i in range(4)]>>> dict([(i, chr(65+i)) for i in range(4)])
http://learnyouahaskell.com/starting-out#im-a-list-comprehension
Sou foda
search_list = lambda l,e : [ [ idx for idx, element in enumerate(l) if element ==
element_f ] for element_f in e]
LambdaLambdas are basically anonymous functions that are used because we need some functions only once. Normally, we make a lambda with the sole purpose of passing it to a higher-order function.
http://learnyouahaskell.com/higher-order-functions#lambdas
LambdaLambdas are basically anonymous functions that are used because we need some functions only once. Normally, we make a lambda with the sole purpose of passing it to a higher-order function.
http://learnyouahaskell.com/higher-order-functions#lambdas
Lambda>>> lambda x: x % 2
http://learnyouahaskell.com/higher-order-functions#lambdas
Lambda>>> is_even = lambda x: x % 2
http://learnyouahaskell.com/higher-order-functions#lambdas
Lambda>>> is_even = lambda x: x % 2>>> is_even<function <lambda> at 0x2a3d050>
http://learnyouahaskell.com/higher-order-functions#lambdas
search_list = lambda l,e : [ [ idx for idx, element in enumerate(l) if element ==
element_f ] for element_f in e]
Built-in Functions>>> for mes in enumerate (['jan', 'fev', 'mar']):... print mes(0, 'jan')(1, 'fev')(2, 'mar')
Built-in Functions>>> for mes in enumerate (['jan', 'fev', 'mar']):... print mes(0, 'jan')(1, 'fev')(2, 'mar')
outras built-in functions: ● filter● map● reduce
Built-in Functions>>> for mes in enumerate (['jan', 'fev', 'mar']):... print mes(0, 'jan')(1, 'fev')(2, 'mar')
outras built-in functions: ● filter● map● reduce
Funções de alta ordem
Filterfilter(...)
filter(function or None, sequence) -> list, tuple or string
Return those items of sequence for which function(item) is true. [....]
>>> filter(lambda x: x % 2 == 0, range(10))
Filterfilter(...)
filter(function or None, sequence) -> list, tuple or string
Return those items of sequence for which function(item) is true. [....]
>>> is_even = lambda x: x % 2 == 0>>> filter(is_even, range(10))
Mapmap(...)
map(function, sequence[, sequence, ...]) -> list
Return a list of the results of applying the function to the items of the argument sequence(s). [....]
>>> map(lambda s: s.upper(), ['a', 'b', 'c'])
Reducereduce(...)
reduce(function, sequence[, initial]) -> value
Apply a function of two arguments cumulatively to the items of a sequence, from left to right, so as to reduce the sequence to a single value. [....]
>>> reduce(lambda x,y: x * y, range(1, 4))>>> reduce(lambda x, y: x + y, ['a', 'b', 'c', 'd'])
Sua High Order Functiondef f(x):
return x + 1
def g(function, x):return function(x) + function (x + 1)
print g(f, 1)
Sua High Order Functiondef f(x):
return x + 1
def g(function, x):return function(x) + function (x + 1)
print g(f, 1)
not bad
Porque aprender haskell me fez um programador
python melhor?
Consegui entendermelhor o
código do Marcel!
Consegui entender melhor o código
de outras pessoas!
Consegui entender melhor a minha
linguagem!
Consegui entender melhor o meu
framework!
Resumindo
Domine sua linguagem
Evolua com a sua linguagem
Domine outras linguagens(Tanto quanto)
Entenda que linguagens são
escolhas
Seja o principal crítico das suas
escolhas
Para saber mais:
from functional import *
OBRIGADO!