Created
March 7, 2021 05:49
-
-
Save romulogarofalo/b5a4e6bc313ec5b7266c8fa1bc0b4c5e to your computer and use it in GitHub Desktop.
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 Exercicios3 where | |
media:: [Double] -> Double | |
media xs = foldl (\x y -> x + y) 0.0 xs / foldl (\x _ -> x + 1) 0.0 xs | |
data Correncia = Dolar | Real deriving (Show, Eq) | |
data Dinheiro = Dinheiro { valor:: Double, correncia:: Correncia } deriving Show | |
converteToDolar :: Dinheiro -> Dinheiro | |
converteToDolar (Dinheiro valor Dolar) = (Dinheiro valor Dolar) | |
converteToDolar (Dinheiro valor Real) = (Dinheiro (valor*0.18) Dolar) | |
operaVariosDinheiros :: [Dinheiro] -> (Dinheiro -> Dinheiro)-> [Dinheiro] | |
operaVariosDinheiros xs func = map func xs | |
pegaDolar :: Dinheiro -> Bool | |
pegaDolar (Dinheiro _ Dolar) = True | |
pegaDolar (Dinheiro _ Real) = False | |
pegaVariosDolar :: [Dinheiro] -> [Dinheiro] | |
pegaVariosDolar xs = filter(\x -> pegaDolar x) xs | |
somaVariosDolares :: [Dinheiro] -> Double | |
somaVariosDolares xs = foldl (\y (Dinheiro valor tipo) -> valor + y) 0.0 $ pegaVariosDolar xs | |
contaDolar :: [Dinheiro] -> Int | |
contaDolar xs = length $ pegaVariosDolar xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment