[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / misc / examples / io / io008 / Main.hs
diff --git a/ghc/misc/examples/io/io008/Main.hs b/ghc/misc/examples/io/io008/Main.hs
new file mode 100644 (file)
index 0000000..51685c9
--- /dev/null
@@ -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)