Skip to content

Instantly share code, notes, and snippets.

@romulogarofalo
Created August 14, 2019 02:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romulogarofalo/63c2d7383d13050cbdebdf00332291d2 to your computer and use it in GitHub Desktop.
Save romulogarofalo/63c2d7383d13050cbdebdf00332291d2 to your computer and use it in GitHub Desktop.
Aula1. todo o conteúdo do primeiro video ensinando Haskell
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]
@matheusfs99
Copy link

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 seria xs = [length 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