Advertisement
randykaur

haskell-last class

Oct 11th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. lista :: [Int] -> [Int] -> [Int]
  2. lista [] _ = []
  3. lista (a:b) s | elem a s == True = lista b s
  4. | otherwise = a : lista b s
  5.  
  6. dif :: [Int] -> [Int] -> [Int]
  7. dif a b = [ x | x <- a, not (elem x b) ]
  8.  
  9.  
  10. quickSort :: [Int] -> [Int]
  11. quickSort [] = []
  12. quickSort (cabeca:cauda) = quickSort [y | y<- cauda, y < cabeca]
  13. ++ [cabeca]
  14. ++ quickSort [y | y <- cauda, y>=cabeca]
  15.  
  16. maior :: (Int, Int) -> Int
  17. maior (a,b) = if (a>b) then a else b
  18.  
  19. --polimorfismo: apenas muda ->(int,float,char)<- // faz uma geral
  20. maior2 :: Ord x=> (x,x) -> x --identifica classe para conseguir fazer operacao "maior que"
  21. maior2 (a,b) = if (a>b) then a else b
  22.  
  23. f :: Double -> Double
  24. f x = let a = x^2 --faz x² em a
  25. in a^2+2*a+1
  26.  
  27. dobra :: Int -> Int
  28. dobra n = n+n
  29.  
  30. dobraLst :: [Int] -> [Int]
  31. dobraLst [] =[]
  32. dobraLst (este:aqueles) = (dobra este):(dobraLst aqueles)
  33.  
  34. mapInt :: (Int -> Int) -> [Int] -> [Int]
  35. mapInt f [] = []
  36. mapInt f (este:aqueles) = (f este) : (mapInt f aqueles)
  37.  
  38. quadra :: Int -> Int
  39. quadra n = n*n
  40.  
  41. mudaTodos :: Bool -> [Int] -> [Int]
  42. mudaTodos f lista = if f
  43. then mapInt dobra lista
  44. else mapInt quadra lista
  45.  
  46. menu :: IO()
  47. menu = do putStr "EU//AQUI"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement