Created
August 14, 2019 02:46
-
-
Save romulogarofalo/63c2d7383d13050cbdebdf00332291d2 to your computer and use it in GitHub Desktop.
Aula1. todo o conteúdo do primeiro video 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 Aula1 where | |
adicionaDois :: Int -> Int | |
adicionaDois x = x + 2 | |
somaTres :: Int -> Int -> Int -> Int | |
somaTres x y z = x + y + z | |
adicionaQuatro :: [Int] -> [Int] | |
adicionaQuatro xs = [x + 4 | x <- xs, (mod x 2) /= 0] | |
-- ex1: | |
-- gere essas listas. | |
geraLista1 :: [Int] | |
geraLista1 = [x | x <- [1..20], (mod x 2) /= 1] | |
-- [2,4,6,8,10,12,14,16,18,20] | |
geraLista2 :: [Int] | |
geraLista2 = [x | x <- [1..20], 7 /= x, ((mod x 2 /= 1) || (x < 10)) ] | |
-- [1,2,3,4,5,6,8,9,10,12,14,16,18,20] | |
geraLista3 :: [Double] | |
geraLista3 = [(x * 0.1) + 1 | x <- [1..7]] | |
-- [1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7] | |
-- ex2StringParImpar :: [String] -> [Bool] | |
-- ex2StringParImpar xs = [mod (length x) 2 /= 0 | x <- xs] | |
-- ["maca","banana","abacaxi"] | |
-- ex2: | |
-- verifique se uma String é impar ou nao retorne Bool | |
ex2StringParImpar :: String -> Bool | |
ex2StringParImpar x = mod (length x) 2 /= 0 | |
-- ex3: | |
-- escreva uma funcao que receba um vetor de | |
-- Strings e retorne uma lista com o tamanho de | |
-- cada String as palavras de tamanho par devem | |
-- ser excluidas da lista retornada | |
ex3ListaStringPar :: [String] -> [String] | |
ex3ListaStringPar xs = [x | x <- xs, mod (length x) 2 /= 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
no exercicio 3 pede pra retornar uma lista com o tamanho das strings. essa função tá retornando a string. então a assinatura deveria ser
[String] -> [Int]
e a list comprehension seriaxs = [length x | x <- xs, mod (length x) 2 /= 0]