>>5 here, i'm done
module Main
where
import IO
main = do
hSetBuffering stdin LineBuffering
doLoop
doLoop = do
putStrLn "Do you want to [read] a file, [write] a file or [quit]? "
command <- getLine
case command of
"quit" -> return ()
"read" -> do doRead
doLoop
"write" -> do doWrite
doLoop
_ -> do putStrLn ("I don't understand the command " ++ command ++ ".")
doLoop
doRead = do
putStrLn "Enter a file name to read:"
filename <- getLine
bracket (openFile filename ReadMode) hClose
(\h -> do contents <- hGetContents h
putStrLn contents)
doWrite = do
putStrLn "Enter a file name to write:"
filename <- getLine
putStrLn "Enter text (dot on a line by itself to end):"
bracket (openFile filename WriteMode) hClose
startWriting
startWriting h = do
line <- getLine
case line of
"." -> return ()
_ -> do hPutStrLn h line
startWriting h
REFACTOR MY CODE