[project @ 2001-05-18 16:54:04 by simonmar]
[ghc-hetmet.git] / ghc / tests / lib / IO / openFile004.hs
1 -- !!! Open a non-existent file for writing
2
3 import Char
4 import IO
5 import Directory
6 import Monad
7
8 file = "openFile004.out"
9
10 main = do
11   b <- doesFileExist file
12   when b (removeFile file)
13
14   h <- openFile file WriteMode
15   hPutStr h "hello world\n"
16   hClose h
17
18   h <- openFile file ReadMode
19   let loop = do
20         b <- hIsEOF h 
21         if b then return () 
22              else do c <- hGetChar h; putChar c; loop
23   loop