[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / misc / examples / io / io008 / Main.hs
1 import LibDirectory (removeFile)
2
3 main =
4     openFile "io008.in" ReadMode >>= \ hIn ->
5     openFile "io008.out" ReadWriteMode >>= \ hOut ->
6     removeFile "io008.out" >>
7     hGetPosn hIn >>= \ bof ->
8     copy hIn hOut >>
9     hSetPosn bof >>
10     copy hIn hOut >>
11     hSeek hOut AbsoluteSeek 0 >>
12     hGetContents hOut >>= \ stuff ->
13     putStr stuff
14
15 copy :: Handle -> Handle -> IO ()
16 copy hIn hOut =
17     try (hGetChar hIn) >>=
18     either (\ EOF -> return ()) ( \ x -> hPutChar hOut x >> copy hIn hOut)