Idris-dev/test/io001/test004.idr
Edwin Brady bf4bdcc31e Change file operation names
Old names still work with a deprecation warning. New names are intended
to be more self consistent.
2015-12-14 20:14:03 +00:00

31 lines
938 B
Idris

module Main
mwhile : (test : IO Bool) -> (body : IO ()) -> IO ()
mwhile t b = do v <- t
case v of
True => do b
mwhile t b
False => return ()
dumpFile : String -> IO ()
dumpFile fn = do { Right h <- openFile fn Read
mwhile (do { -- putStrLn "TEST"
x <- fEOF h
return (not x) })
(do { Right l <- fGetLine h
putStr l })
closeFile h }
main : IO ()
main = do { Right h <- openFile "testfile" Write
fPutStr h "Hello!\nWorld!\n...\n3\n4\nLast line\n"
closeFile h
putStrLn "Reading testfile"
Right f <- readFile "testfile"
putStrLn f
putStrLn "---"
dumpFile "testfile"
putStrLn "---"
}