Created
August 19, 2013 16:43
-
-
Save qoelet/6271192 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- 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