Those are the slides (pt_BR) used to give a small overview about Haskell before starting the coding dojo at Liferay Recife. Our coding dojo used the word-wrapping kata (http://codingdojo.org/kata/WordWrap) and the results can be seen here: https://github.com/brandizzi/haskell-dojo-word-wrap
20. Linguagem funcional pura
● Descrição, mas não execução, de operações
entrada e saída.
● Execução de operações de entrada e saída fica
a cargo do runtime.
● Operações de entrada e saída são descritas
pelo tipo IO, que é uma...
24. Linguagem tipada
● Estaticamente tipada: tipos de expressões já
estão definidos em tempo de compilação.
● Fortemente tipada: sem coerções.
● Tipagem implícita.
25. > let n = True
> :t n
n :: Bool
> n && False
False
> n && 0
<interactive>:67:6:
No instance for (Num Bool) arising from
the literal ‘0’
In the second argument of ‘(&&)’, namely
‘0’
In the expression: n && 0
In an equation for ‘it’: it = n && 0
28. > let l = [True, False, False]
> :t l
l :: [Bool]
> let s = "Hello"
> :t s
s :: [Char]
> let m = Just True
> :t m
m :: Maybe Bool
> let t = (True, 'a', "one string")
> :t t
t :: (Bool, Char, [Char])
29. > :t [True]
[True] :: [Bool]
> :t []
[] :: [t]
> :t Just 'a'
Just 'a' :: Maybe Char
> :t Nothing
Nothing :: Maybe a
30. Linguagem preguiçosa
● Avaliação preguiçosa (“lazy evaluation”).
● Cálculo de valores é postergado até serem
realmente necessários.
31. > [1..5]
[1,2,3,4,5]
> let l = [1..]
> l !! 0
1
> l !! 5
6
> l !! 300000
300001
> length l
^CInterrupted.
32. > let n = 1
> let n = n+1
> n
*** Exception: <<loop>>
33. > let n = 2
> n + (2 :: Integer)
4
> :t n + (2 :: Integer)
n + (2 :: Integer) :: Integer
> n + (2.0 :: Float)
4.0
> :t n + (2.0 :: Float)
n + (2.0 :: Float) :: Float
> (2 :: Integer) + (2.0 :: Float)
<interactive>:26:19:
Couldn't match expected type ‘Integer’ with actual type ‘Float’
In the second argument of ‘(+)’, namely ‘(2.0 :: Float)’
In the expression: (2 :: Integer) + (2.0 :: Float)
In an equation for ‘it’: it = (2 :: Integer) + (2.0 :: Float)
41. Linguagem fortemente tipada
● System F.
● Sistema de tipos extremamente poderoso.
● Não só protege como facilita modelagem.
● “Making illegal states unrepresentable”
43. > data EstadoSemaforo = Verde | Amarelo | Vermelho deriving (Show, Eq)
> let podePassar es = es /= Vermelho
> podePassar Verde
True
> podePassar Amarelo
True
> podePassar Vermelho
False
> Verde
Verde
44. > data Casa = Endereço { rua :: String, numero :: Integer } deriving (Show, Eq)
> let e = Endereço "Rua Jacó Velosino" 390
> rua e
"Rua Jac243 Velosino"
> numero e
390
45. data Maybe a = Just a | Nothing
data Either a b = Left a | Right b
data [a] = [] | a : [a]
46. Controle de fluxo
● If then else
● Pattern matching
● Guardians
● Recursão
● Folding/mapping/filtering etc.