Add stage2/ghci to ghc-api's import list.
[ghc-hetmet.git] / ghc / misc / examples / io / io008 / Main.hs
1 import IO -- 1.3
2 import GHCio
3
4 import Directory (removeFile)
5
6 main =
7     openFile "io008.in" ReadMode >>= \ hIn ->
8     openFile "io008.out" ReadWriteMode >>= \ hOut ->
9     removeFile "io008.out" >>
10     hGetPosn hIn >>= \ bof ->
11     copy hIn hOut >>
12     hSetPosn bof >>
13     copy hIn hOut >>
14     hSeek hOut AbsoluteSeek 0 >>
15     hGetContents hOut >>= \ stuff ->
16     putStr stuff
17
18 copy :: Handle -> Handle -> IO ()
19 copy hIn hOut =
20     tryIO (hGetChar hIn) >>=
21     either (\ err -> if isEOFError err then return () else error "copy") ( \ x -> hPutChar hOut x >> copy hIn hOut)