blob: 4124abb0debe2ace7d2ac210f2b1864b24de83c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
-- !!! Open a non-existent file for writing
import Control.Monad
import Data.Char
import System.Directory
import System.IO
file = "openFile004.out"
main = do
b <- doesFileExist file
when b (removeFile file)
h <- openFile file WriteMode
hPutStr h "hello world\n"
hClose h
h <- openFile file ReadMode
let loop = do
b <- hIsEOF h
if b then return ()
else do c <- hGetChar h; putChar c; loop
loop
|