-- Support for text I\/O.
+ -- * File-at-a-time operations
-- * Operations on handles
-import Prelude hiding (getContents, getLine, interact, putStr, putStrLn)
-import System.IO (Handle, stdin, stdout)
+import Prelude hiding (appendFile, getContents, getLine, interact, putStr,
+ putStrLn, readFile, writeFile)
+import System.IO (Handle, hPutChar, stdin, stdout)
+import qualified Data.ByteString as B
+import Data.Text.Encoding (decodeUtf8, encodeUtf8)
+-- | The 'readFile' function reads a file and returns the contents of
+-- the file as a string. The entire file is read strictly, as with
+readFile :: FilePath -> IO Text
+readFile = fmap decodeUtf8 . B.readFile
+-- | Write a string to a file. The file is truncated to zero length
+-- before writing begins.
+writeFile :: FilePath -> Text -> IO ()
+writeFile p = B.writeFile p . encodeUtf8
+-- | Write a string the end of a file.
+appendFile :: FilePath -> Text -> IO ()
+appendFile p = B.appendFile p . encodeUtf8
+-- | Read the remaining contents of a handle as a string.
hGetContents :: Handle -> IO Text
h = undefined
+-- | Read a single line from a handle.
hGetLine :: Handle -> IO Text
+-- | Write a string to a handle.
hPutStr :: Handle -> Text -> IO ()
+-- | Write a string to a handle, followed by a newline.
hPutStrLn :: Handle -> Text -> IO ()
-hPutStrLn h t =
+hPutStrLn h t =
+-- | The 'interact' function takes a function of type @Text -> Text@
+-- as its argument. The entire input from the standard input device is
+-- passed to this function as its argument, and the resulting string
+-- is output on the standard output device.
interact :: (Text -> Text) -> IO ()
+interact f =
+-- | Read all user input on 'stdin' as a single string.
getContents = hGetContents stdin
+-- | Read a single line of user input from 'stdin'.
+-- | Write a string to 'stdout'.
+-- | Write a string to 'stdout', followed by a newline.
putStrLn :: Text -> IO ()
putStrLn = hPutStrLn stdout
+-- Under GHC 6.10 and earlier, the system I\/O libraries do not
+-- support locale-sensitive I\/O. All data read by functions in this
+-- module is decoded as UTF-8, and before data is written, it is first
+-- Beginning with GHC 6.12, text I\/O is performed using the system or
+-- handle's current locale.