Created
March 6, 2010 05:57
-
-
Save jutememo/323522 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ページ | |
data Page = Page [String] | |
-- 文字列をページに変換 | |
toPage :: String -> Page | |
toPage = Page . lines | |
-- 数値 n を文字幅 width で右揃え | |
padding n width = let num = show n | |
lNum = length num | |
in replicate (width - lNum) ' ' ++ num | |
-- 行に幅 widht で行番号をふる | |
numberingLine width (n, line) = padding n width ++ " " ++ line | |
-- ページに幅 width で行番号をふる | |
numberingPage width (Page cs) = unlines $ map (numberingLine width) numbering | |
where | |
numbering = (zip [1..] cs) | |
main = getContents >>= putStr . numberingPage 6 . toPage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment