Skip to content

Instantly share code, notes, and snippets.

@romulogarofalo
Created June 9, 2020 06:32
Show Gist options
  • Save romulogarofalo/523b019cc8b440246691ce0b6fc7e29b to your computer and use it in GitHub Desktop.
Save romulogarofalo/523b019cc8b440246691ce0b6fc7e29b to your computer and use it in GitHub Desktop.
module Exercicios4 where
-- 1
media :: [Double] -> Double
media z = (foldl (\x y -> x + y) 0 z)
-- 2
pares :: [Int] -> [Int]
pares x = filter (\y -> mod y 2 == 0) x
impares :: [Int] -> [Int]
impares x = filter (\y -> mod y 2 /= 0) x
-- 3
data Correncia = Real | Dolar deriving (Show, Eq)
data Dinheiro = Dinheiro {
valor :: Double,
correncia :: Correncia
} deriving Show
converte :: Dinheiro -> Double
converte (Dinheiro x Real) = x * 4.82
convete (Dinheiro x Dolar) = x / 4.82
filtraDolar :: [Dinheiro] -> [Dinheiro]
filtraDolar z = filter(\(Dinheiro x y) -> y == Dolar) z
somaDolares :: [Dinheiro] -> Double
somaDolares x = foldl (\z (Dinheiro a b)-> a + z) 0 (filtraDolar x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment