-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiotest.hs
More file actions
44 lines (37 loc) · 1.01 KB
/
iotest.hs
File metadata and controls
44 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Main
where
import IO
fileGrab = do
fh <- openFile "foo" ReadMode
contents <- hGetContents fh
putStr(contents)
hClose fh
doRead = do
putStrLn "File to read:"
file <- getLine
putStrLn ("-----Contents of " ++ file ++ "-----")
contents <- readFile file
putStr contents
doWrite = do
putStrLn "File to write:"
file <- getLine
putStrLn "File contents"
contents <- gatherLoop
writeFile file contents
gatherLoop = do
line <- getLine
case line of
"." -> return []
_ -> do rest <- gatherLoop
return $ line ++ "\n" ++ rest
exercise = do
putStrLn "Do you want to [read], [write], or [quit]?"
verb <- getLine
case verb of
"quit" -> return ()
"read" -> doRead
"write" -> doWrite
_ -> exercise
main = do
exercise
-- vim: ts=4 sw=4 et: