diff options
Diffstat (limited to 'ghc/misc/examples/io/io008/Main.hs')
-rw-r--r-- | ghc/misc/examples/io/io008/Main.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ghc/misc/examples/io/io008/Main.hs b/ghc/misc/examples/io/io008/Main.hs new file mode 100644 index 0000000000..51685c9201 --- /dev/null +++ b/ghc/misc/examples/io/io008/Main.hs @@ -0,0 +1,18 @@ +import LibDirectory (removeFile) + +main = + openFile "io008.in" ReadMode >>= \ hIn -> + openFile "io008.out" ReadWriteMode >>= \ hOut -> + removeFile "io008.out" >> + hGetPosn hIn >>= \ bof -> + copy hIn hOut >> + hSetPosn bof >> + copy hIn hOut >> + hSeek hOut AbsoluteSeek 0 >> + hGetContents hOut >>= \ stuff -> + putStr stuff + +copy :: Handle -> Handle -> IO () +copy hIn hOut = + try (hGetChar hIn) >>= + either (\ EOF -> return ()) ( \ x -> hPutChar hOut x >> copy hIn hOut) |