Created
June 9, 2020 06:32
-
-
Save romulogarofalo/523b019cc8b440246691ce0b6fc7e29b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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