Skip to content

Instantly share code, notes, and snippets.

@romulogarofalo
Created June 9, 2020 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romulogarofalo/aebbe8b280555ebdd079ee61bb4fa703 to your computer and use it in GitHub Desktop.
Save romulogarofalo/aebbe8b280555ebdd079ee61bb4fa703 to your computer and use it in GitHub Desktop.
-- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment