-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverseWord.hs
More file actions
59 lines (49 loc) · 1.13 KB
/
reverseWord.hs
File metadata and controls
59 lines (49 loc) · 1.13 KB
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
import Control.Monad
import Data.Char
module Main where
main = do
line <- getLine
if null line
then return "Haha"
else do
putStrLn $ reverseWords line
main
-- "."可以右结合
reverseWords :: String -> String
reverseWords = unwords . map reverse . words
main2 = do
return ()
return "HAHHA"
line <- getLine
return "Blah blah blah"
return 4
putStrLn line
-- 用putChar 实现 putStr
-- putStr :: String -> IO ()
-- putStr [] = return ()
-- putStr (x:xs) = do
-- putChar x
-- putStr xs
main3 = do
c <- getChar
if c /= ' '
then do
putChar c
main3
else return ()
main4 = do
c <- getChar
when (c /= ' ') $ do
putChar c
main4
main5 = forever $ do
putStr "Give me some input: "
l <- getLine
putStrLn $ map toUpper l
main6 = do
colors <- forM [1,2,3,4] (\a -> do
putStrLn $ "Which color do you associate with the number " ++ show a ++ "?"
color <- getLine
return color)
putStrLn "The colors that you associate with 1, 2, 3 and 4 are: "
mapM putStrLn colors