[READ-ONLY] Mirror of https://github.com/shuuji3/normal-haskell-programming-book. Codes for『ふつうのHaskellプログラミング』http://www.loveruby.net/ja/stdhaskell/
421 B
15 lines
1main :: IO ()
2main = do cs <- getContents
3 putStr $ numbering cs
4
5numbering :: String -> String
6numbering cs = unlines $ map format $ zipLineNumber $ lines cs
7
8zipLineNumber :: [String] -> [(Int, String)]
9zipLineNumber xs = zip [1..] xs
10
11format :: (Int, String) -> String
12format (n, line) = rjust 6 (show n) ++ " " ++ line
13
14rjust :: Int -> String -> String
15rjust width s = replicate (width - length s) ' ' ++ s