-
Notifications
You must be signed in to change notification settings - Fork 1
/
class.hs
61 lines (47 loc) · 1021 Bytes
/
class.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import Control.Monad (forM, forM_, forever, when)
main' :: IO ()
main' = do
a <- getLine
b <- getLine
print [a, b]
main'' :: IO ()
main'' = do
res <- sequence [getLine, getLine]
print res
mainMap :: IO ()
mainMap = do
mapM_ print [1, 2, 3]
mainFor :: IO ()
mainFor = do
forM_ [1, 2, 3] $ \i -> do
print i
line <- getLine
print (read line + i)
mainWhen :: IO ()
mainWhen = do
line <- getLine
when (length line < 2) $ do
putStrLn "in the when 'block'"
test <- getLine
putStrLn test
putStrLn "After when block"
-- forever
mainMultiplyForever :: IO ()
mainMultiplyForever = do
forever $ do
a <- getLine
b <- getLine
print $ "Ans: " ++ show (read a * read b)
putStr "test"
mainForM :: IO ()
mainForM = do
putStrLn "Running mainForM"
result <- forM [1, 2, 3] $ \a -> do
b <- getLine
print (a + read b)
return (a ** 2 + read b)
putStrLn "The result is:"
print result
main :: IO ()
main = do
interact $ unwords . map reverse . words