Escolar Documentos
Profissional Documentos
Cultura Documentos
Lucas Albertins
• Valores
• ..., −3, −2, −1, 0, 1, 2, 3, ... :: Int
• Funções:
• +, *, −, ^, div , mod, abs :: Int −> Int −> Int
• >, >=, ==, /=, <=, < :: Int −> Int −> Bool
1
Números Inteiros - Exemplos
> 2 ^3
;8
> div 14 3
;4
> 14 ‘ div ‘ 3
;4
> mod 14 3
;2
> 14 ‘ mod‘ 3
;2
2
Booleanos
• Valores
• True, False :: Bool
• Funções:
• &&, || :: Bool −> Bool −> Bool
• not :: Bool −> Bool
3
Booleanos - Exemplos
−−outra forma
eXor : : Bool −> Bool −> Bool
eXor True x = not x
eXor F a l s e x = x
4
Booleanos - Exemplos
ao invés de
vendasNulas : : I n t −> Bool
vendasNulas n
| vendas n == 0 = True
| otherwise = False
5
Caracteres
• Valores
• ‘ a‘ , ‘ b ‘, ... :: Char
• Funções:
• ord :: Char −> Int
• chr :: Int −> Char
6
Caracteres - Exemplo
o f f s e t = fromEnum ‘ A ‘ − fromEnum ‘ a ‘
7
Strings
• Valores
• "abc", "casa" :: String
• Funções:
• ++ :: String −> String −> String
• show :: ? −> String (overloading)
8
Strings - Exemplos
String e valores
> show ( 2 + 3 )
> show ( True | | F a l s e )
9
Float e Double - Ponto flutuante
• Valores
• 22.3435
• 23.4e−4
• Funções:
• +,−,*,/ :: Float −> Float −> Float
• pi :: Float
• ceiling , floor , round :: Float −> Int
• fromIntegral :: Int −> Float
• read :: String −> Float
• show :: Float −> String
10
Exercícios
11
Exercícios
12
Exercícios
imprimeTabela : : I n t −> S t r i n g
imprimeTabela n = cabecalho
++ imprimeSemanas n
++ imprimeTotal n
++ imprimeMedia n
13
Estruturas de dados - Tuplas
addPair : : ( I n t , I n t ) −> I n t
addPair ( x , y ) = x + y
s h i f t : : ( ( I n t , I n t ) , I n t ) −> ( I n t , ( I n t , I n t ) )
shift (( x , y ) , z ) = (x , ( y , z ))
14
Exemplo - Equação do segundo grau
• ax2 + bx + c = 0.0
• Duas raízes, se b2 > 4.0 ∗ a ∗ c
• Uma raiz, se b2 = 4.0 ∗ a ∗ c
• Não possui raízes, se (−b ± sqrt(b2 − 4ac))/2a)
• Calculando as raízes: (−b ± sqrt(b2 − 4ac))/2a)
15
Resolução bottom-up
16
Resolução bottom-up
17
Sinônimos de tipos
type Name = S t r i n g
type Age = I n t
type Phone = I n t
type Person = ( Name , Age , Phone )
18
Exercícios
19
Exercícios
20
Exercícios
21
Bibliografia
22