Skip to content

Instantly share code, notes, and snippets.

@kana
Created February 8, 2011 13:02
Show Gist options
  • Save kana/816409 to your computer and use it in GitHub Desktop.
Save kana/816409 to your computer and use it in GitHub Desktop.
data ShellState = ShellState {
count :: Int
}
main = do
ls <- getContents
s <- return $ ShellState 0
loop s $ lines ls
loop :: ShellState -> [String] -> IO ()
loop s [] = return ()
loop s (l:ls) = do
x <- executeCommand s l
putStrLn $ (show $ count $ fst x) ++ ", " ++ (snd x)
loop (fst x) ls
executeCommand :: ShellState -> String -> IO (ShellState, String)
executeCommand s line = return (ShellState $ 1 + count s, line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment