Advertisement
Vladi1442

Untitled

Aug 8th, 2022
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. main :: IO()
  2. main = do
  3.     print $ "hello world"
  4.     print $ "Enter some text right in console!"
  5.  
  6. plus :: Int -> Int -> Int
  7. plus x y = x + y
  8.  
  9. minus :: Int -> Int -> Int
  10. minus x y = x - y
  11.  
  12. mult :: Int -> Int -> Int
  13. mult x y = x * y
  14.  
  15. divs :: Int -> Int -> Int
  16. divs x y = x / y
  17.  
  18. divs' :: Int -> Int -> Int
  19. divs' x y = div x y
  20.  
  21. mods :: Int -> Int -> Int
  22. mods x y = mod x y
  23.  
  24. addThree :: Int -> Int -> Int -> Int
  25. addThree x y z = x + y + z
  26.  
  27. factorial :: Int -> Int
  28. factorial n = product [1..n]
  29.  
  30. bigger :: Int -> Int -> Bool
  31. bigger x y = if x > y then x else y
  32.  
  33. lucky :: Int -> String
  34. lucky 7 = "You got the right number!"
  35. lucky x = "Sorry, you're out of luck!"
  36.  
  37. sayMe :: Int -> String
  38. sayMe 1 = "One"
  39. sayMe 2 = "Two"
  40. sayMe 3 = "Three"
  41. sayMe 4 = "Four"
  42. sayMe 5 = "Five"
  43. sayMe x = "Not between 1 and 5"
  44.  
  45. factorial' :: Int -> Int
  46. factorial' 0 = 1
  47. factorial' 1 = 1
  48. factorial' n = n * factorial (n-1)
  49.  
  50. charName :: Char -> String
  51. charName 'a' = "Albert"
  52. charName 'b' = "Broseph"
  53. charName 'c' = "Cercil"
  54.  
  55. addVectors1 :: (Ord a, Num a) => (a,a) -> (a,a) -> (a,a)
  56. addVectors1 x y = (fst x + fst y, snd x + snd y)
  57.  
  58. addVectors2 :: (Ord a, Num a) => (a,a) -> (a,a) -> (a,a)
  59. addVectors2 (x1,y1) (x2,y2) = (x1+x2,y1+y2)
  60.  
  61. first :: (a,b,c) -> a
  62. first (x, _, _) = x
  63.  
  64. second :: (a,b,c) -> b
  65. second (_, y, _) = y
  66.  
  67. third :: (a,b,c) -> c
  68. third (_, _, z) = z
  69.  
  70. head :: [Int] -> Int
  71. head [] = error "Can't call head on empty list, dummy"
  72. head (x:_) = x
  73.  
  74. -- here we don't care about our first argument
  75.  
  76. length :: [Int] -> Int
  77. length [] = 0
  78. length (_:xs) = 1 + length xs
  79.  
  80. -- but here we are interested in our first argument
  81.  
  82. sum :: [Int] -> Int
  83. sum [] = 0
  84. sum (x:xs) = x + sum xs
  85.  
  86. bmiTell :: (RealFloat a) => a -> String
  87. bmiTell bmi
  88.     | bmi <= 18.5 = "You are underweight"
  89.     | bmi <= 25.0 = "You are normal weight"
  90.     | bmi <= 30.0 = "You are overweight"
  91.     | otherwise = "If you contunue to eat, you are gonna die"
  92.  
  93. bmiTell1 :: (RealFloat a) => a -> a -> String
  94. bmiTell1 weight height
  95.     | weight / height ^ 2 <= 18.5 = "You are underweight"
  96.     | weight / height ^ 2 <= 25.0 = "You are normal weight"
  97.     | weight / height ^ 2 <= 30.0 = "You are overweight"
  98.     | otherwise = "You are a whale, congratulations"
  99.  
  100. bmiTell2 :: (RealFloat a) => a -> a -> String
  101. bmiTell2 weight height
  102.     | bmi <= 18.5 = "You are underweight"
  103.     | bmi <= 25.0 = "You are normal weight"
  104.     | bmi <= 30.0 = "You are overweight"
  105.     | otherwise = "You are a whale, congratulations"
  106.         where
  107.             bmi = weight / height ^ 2
  108.  
  109. bmiTell3 :: (RealFloat a) => a -> a -> String
  110. bmiTell3 weight height
  111.     | bmi <= skinny = "You are underweight"
  112.     | bmi <= normal = "You are normal weight"
  113.     | bmi <= overweight = "You are overweight"
  114.     | otherwise = "You are a whale, congratulations"
  115.  
  116. max1 :: Int -> Int -> Int
  117. max1 a b
  118.     | a > b = a
  119.     | otherwise = b
  120.  
  121. min1 :: Int -> Int -> Int
  122. min1 a b
  123.     | a > b = b
  124.     | otherwise = a
  125.    
  126. maxThree :: Int -> Int -> Int -> Int
  127. maxThree a b c = if (a > b) && (a > c) then a else if (b > a) && (b > c) then b else c
  128.  
  129. maxThree1 :: Int -> Int -> Int -> Int
  130. maxThree1 a b c
  131.     | (a > b) && (a > c) = a
  132.     | (b > a) && (b > c) = b
  133.     | otherwise = c
  134.  
  135. myCompare :: Int -> Int -> String
  136. myCompare a b
  137.     | a > b = "GT"
  138.     | a < b = "LT"
  139.     | otherwise = "EQ"
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement