Skip to content

Instantly share code, notes, and snippets.

@funrep
Last active December 16, 2015 21:00
Show Gist options
  • Select an option

  • Save funrep/5496861 to your computer and use it in GitHub Desktop.

Select an option

Save funrep/5496861 to your computer and use it in GitHub Desktop.
addNumbers :: Int -> String -> String
addNumbers x (y:ys)
| null ys = []
| y == '\n' = ("\n" ++ show x ++ " ") ++ (addNumbers (x + 1) ys)
| otherwise = y : (addNumbers x ys)
main = interact (addNumbers 1)
@quchen
Copy link
Copy Markdown

quchen commented May 1, 2013

-- Shorter version:
main = interact catb

catb :: String -> String
catb = unlines . zipWith addNumber [1..] . lines
    where addNumber n s = show n ++ " " ++ s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment