Created
June 9, 2020 06:32
Revisions
-
romulogarofalo created this gist
Jun 9, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,95 @@ -- hj na aula 3 vamos falar de, funcoes de alta ordem, currying, 3 famoso que todo javascriptero usa, $, |> module Aula3 where -- (\x -> x*2) 4 -- (\x xs -> x : reverse xs) 'A' "UOIE" -- FUNÇÕES DE ALTA ORDEM ev :: (Int -> Int) -> Int ev f = 1 + f 5 dobro :: Int -> Int dobro x = 2*x triplo :: Int -> Int triplo x = 3*x -- aqui testa -- CURRYING somarTresNum :: Int -> Int -> Int -> Int somarTresNum x y z = x+y+z somarCurr :: Int -> Int somarCurr = somarTresNum 4 5 somarTresNum :: Int -> Int -> (Int -> Int) -- EXEMPLO DE FUNCOES DE ALTA ORDEM -- FAMOSOS map filter reduce do javascript, entao ja tinha no Haskell -- map (\x -> x * 2) [1..10] -- filter (x -> mod x 2 == 0) [1..20] -- reduce (\x y -> x + y) [1..10] 0 -- GUARDS GUARDS imc :: Double -> Double -> String imc p a | p/(a*a) <= 18.5 = "Abaixo do peso" | p/(a*a) < 25.0 = "Peso ideal" | p/(a*a) <= 30 = "Acima do peso" | otherwise = "Obesidade" imc' p a | valorImc <= 18.5 = "Abaixo do peso" | valorImc < 25.0 = "Peso ideal" | valorImc <= 30 = "Acima do peso" | otherwise = "Obesidade" where valorImc = p/(a*a) -- RECURSIVIDADE fat n | n <= 1 = 1 | otherwise = n*fat(n-1) -- usando patterning matching reverse' :: String -> String reverse' [] = [] reverse' (x:xs) = reverse' xs ++ [x] -- exercicios -- 1 -- Faça uma função que retorne a média de um [Double] , -- usando foldl -- 2 -- Implemente uma função que filtre os números pares e -- outra que filtre os ímpares de uma lista recebida via parâmetro. -- 3 -- Implemente o tipo Dinheiro que contenha os campos -- valor e correncia ( Real ou Dolar ), e uma função que -- converta todos os "dinheiros" de uma lista para dólar (e outra para -- real). Com isso, implemente funções para: -- Filtrar todos os Dolares de uma lista de Dinheiro . -- Somar todos os Dolares de uma lista. -- Contar a quantidade de Dolares de uma lista.