Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created March 6, 2010 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jutememo/323522 to your computer and use it in GitHub Desktop.
Save jutememo/323522 to your computer and use it in GitHub Desktop.
-- ページ
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