Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created August 19, 2013 16:43
Show Gist options
  • Save qoelet/6271192 to your computer and use it in GitHub Desktop.
Save qoelet/6271192 to your computer and use it in GitHub Desktop.
-- read a text file
-- print a line, wait for return by user, repeat. exits when no more lines to print
import System.Environment
import System.IO
import System.Exit
parse ["-h"] = putStrLn "./text_reader [-h] file" >> exitWith ExitSuccess
parse [f] = readFile f
waitAndPrint [] = putStrLn "-- end" >> exitWith ExitSuccess
waitAndPrint (x:xs) = do
c <- getChar
putStrLn x
waitAndPrint xs
main = do
args <- getArgs
f <- parse args
let contents = lines f
firstLine = head contents
rest = tail contents
putStrLn firstLine
waitAndPrint rest
-- $ ghc --make text_reader
-- $ ./text_reader -h
-- ./text_reader [-h] file
-- $ ./text_reader test.txt
-- i am a file
--
-- with a few
--
-- text lines!
-- -- end
-- $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment