Created
August 14, 2019 02:50
-
-
Save romulogarofalo/1a30213991456f7e8f0ec50215079d4f to your computer and use it in GitHub Desktop.
Aula2. com todo o conteúdo mostrado no video 2 ensinando Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Aula2 where | |
data Dia = Segunda | Terca | Quarta | Quinta | Sexta | Sabado | Domingo | |
-- :t Segunda | |
diaDoQue :: Dia -> String | |
diaDoQue Sabado = "Festa :D" | |
diaDoQue Domingo = "Ressaca :(" | |
diaDoQue _ = "Trabalho!" | |
fib :: Int -> Int | |
fib 0 = 0 | |
fib 1 = 1 | |
fib n = fib (n - 1) + fib (n - 2) | |
-- campos com construtores | |
data Pessoa = Fisica String Int | Juridica String | |
nomeIdade :: Pessoa -> (String, String) | |
nomeIdade (Fisica x y) = ("Nome: " ++ x, "Idade: " ++ show y) | |
nomeIdade (Juridica x) = ("Nome: " ++ x, "Nao ha idade") | |
data Tipo = Fogo | Planta | Agua deriving Show | |
-- data Pokemon = Pokemon String Tipo Int | |
data Pokemon = | |
Pokemon { | |
nome :: String, | |
tipo :: Tipo, | |
nivel:: Int | |
} deriving Show | |
levelUp :: Pokemon -> Pokemon | |
levelUp (Pokemon x y z) = (Pokemon x y (z+1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment