Advertisement
vencinachev

FunctionReturn

Nov 21st, 2021
1,322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. main :: IO()
  2. main = do
  3.   putStr "Enter number 1: "
  4.   line1 <- getLine
  5.   putStr "Enter number 2: "
  6.   line2 <- getLine
  7.   putStr "Enter operation: "
  8.   op <- getLine
  9.   let num1 = read line1 :: Int
  10.   let num2 = read line2 :: Int
  11.   print ((getOperation op) num1 num2)
  12.  
  13.  
  14. getOperation :: String -> (Int->Int->Int)
  15. getOperation "Plus" = \x y -> x + y
  16. getOperation "Minus" = \x y -> x - y
  17. getOperation "Mult" = \x y -> x * y
  18. getOperation "Div" = \x y -> x `div` y
  19. getOperation "Mod" = \x y -> x `mod` y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement