SHARE
TWEET

Day2

vencinachev Oct 25th, 2019 129 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type Student = (String, Int)
  2. s1 :: Student
  3. s2 :: Student
  4. s1 = ("Ivan Petrov", 111213)
  5. s2 = ("Hristo Hristov", 102030)
  6.  
  7. mult4 :: (Int, Int, Int, Int) -> Int
  8. mult4 (x, y, z, t) = x*y*z*t
  9.  
  10. sort2 :: (Int, Int) -> (Int, Int)
  11. sort2 (x, y) = if x >= y then (x, y) else (y, x)
  12.  
  13. fib :: Int -> Int
  14. fib n
  15.     | n == 1 = 1
  16.     | n == 2 = 1
  17.     | n > 2  = fib (n-2) + fib (n-1)
  18.     | otherwise = error "Not defined"
  19.  
  20. fibStep :: (Int, Int) -> (Int, Int)
  21. fibStep (u, v) = (u, u+v)
  22.  
  23.  
  24. fibPair :: Int -> (Int, Int)
  25. fibPair n = (fib(n), fib(n + 1))
  26.  
  27. toEnd :: a -> [a] -> [a]
  28. toEnd x l = l ++ [x]
  29.  
  30. sumPairs :: [(Int, Int)] -> [Int]
  31. sumPairs pL = [x + y | (x, y) <- pL]
  32.  
  33. digit :: Char -> Bool
  34. digit ch = ch >= '0' && ch <= '9'
  35.  
  36. all_digits :: String -> String
  37. all_digits str = [ch | ch <- str,  digit ch]
  38.  
  39. allEven :: [Int] -> Bool
  40. allEven x = (x == [a | a <- x, even a])
  41.  
  42. allOdd :: [Int] -> Bool
  43. allOdd x = (x == [a | a <- x, odd a])
  44.  
  45. revWords :: String -> String
  46. revWords input = (unwords . reverse . words) input
  47.  
  48. sumMy :: [Int] -> Int
  49. sumMy [] = 0
  50. sumMy (x:xs) = x + sum xs
  51.  
  52. concatMy :: [[a]] -> [a]
  53. concatMy [] = []
  54. concatMy (x : xs) = x ++ concat xs
  55.  
  56. calssify :: Int -> String
  57. classify age = case age of 0 -> "newborn"
  58.                            1 -> "infant"
  59.                            2 -> "toddler"
  60.                            _ -> "senior citizen"
  61.  
  62. day :: Int -> String
  63. day x = case x of
  64.                 1 -> "Monday"
  65.                 2 -> "Tuesday"
  66.                 3 -> "Wednesday"
  67.                 4 -> "Thursday"
  68.                 5 -> "Friday"
  69.                 6 -> "Saturday"
  70.                 7 -> "Sunday"
  71.                 _ -> "Not defined"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top