-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapslocker.hs
More file actions
36 lines (28 loc) · 924 Bytes
/
capslocker.hs
File metadata and controls
36 lines (28 loc) · 924 Bytes
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
import Control.Monad
import Data.Char
-- getLine版本
main_getLine = forever $ do
i <- getLine
putStrLn $ map toUpper i
-- getContents版本
main_getContents = do
contents <- getContents
putStrLn (map toUpper contents)
-- 获取少于十个字符的行内容
main_shortLinesOnly = do
contents <- getContents
putStr (shortLinesOnly contents)
-- 未省略参数版shortLinesOnly
shortLinesOnly :: String -> String
shortLinesOnly input =
let allLines = lines input
shortLines = filter (\line -> length line < 10) allLines
result = unlines shortLines
in result
-- interact版 获取少于十个字符的行内容
main = interact shortLinesOnly'
-- 省略参数版shortLinesOnly
shortLinesOnly' :: String -> String
shortLinesOnly' = unlines . filter (\line -> length line < 10) .lines
-- less code版
main_less_code = interact $ unlines . filter ((<10) . length) . lines