Haskell para pythonistas

1,484 views

Published on

Palestra relâmpago apresentada o FISL12, mostrando semelhanças e diferenças entre python e haskell

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,484
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Haskell para pythonistas

    1. 1. haskell para pythonistas @andrewsmedina
    2. 2. porque haskell?• puramente funcional• lazy• um novo paradigma de linguagem
    3. 3. python x haskell• multi paradigma • funcional• dinâmica • estática• interpretada • compilada• recursao • recursao++
    4. 4. python>>> 2+1517
    5. 5. haskellPrelude> 2+1517
    6. 6. pythondef dobro(numero): return numero + numero
    7. 7. haskelldobro numero = numero + numero
    8. 8. pythondef fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-1) + fib(n-2)
    9. 9. haskellfib 0 = 0fib 1 = 1fib n = fib (n-1) + fib (n-2)
    10. 10. python>>> lista = [1,2,3,4,5]>>> [numero*2 for numero in lista][2, 4, 6, 8, 10]
    11. 11. haskellPrelude> let lista = [1,2,3,4,5]Prelude> [x*2 | x <- lista][2,4,6,8,10]
    12. 12. python>>> lista = [1,2,3,4,5]>>> [numero*2 for numero in lista if numero%2][2, 6, 10]
    13. 13. haskellPrelude> let lista = [1,2,3,4,5]Prelude> [numero*2 | numero <- lista, odd numero][2,6,10]
    14. 14. haskellPrelude> [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2][(3,4,5),(6,8,10)]
    15. 15. haskellPrelude> product [1..10]3628800
    16. 16. haskellmain = do firstFactorOver(3)firstFactorOver n = head [trianguleNumber(x) | x <- [1..], length ( factorsOf ( trianguleNumber(x) ) ) > n ]trianguleNumber n = sum[1..n]factorsOf number = 1:[x| x <- [2..number], number `mod` x == 0] ++ [number]
    17. 17. python funcional• itertools• list comprehensions• map, reduce, zip...
    18. 18. como começar?• ghci
    19. 19. http://learnyouahaskell.com

    ×