@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12-- |
23-- Module : Data.Text.IO
34-- Copyright : (c) Bryan O'Sullivan 2009
@@ -34,46 +35,82 @@ import Data.Text (Text)
3435import Prelude hiding (appendFile, getContents, getLine, interact, putStr,
3536 putStrLn, readFile, writeFile)
3637import System.IO (Handle, hPutChar, stdin, stdout)
38+#if __GLASGOW_HASKELL__ <= 610
3739import qualified Data.ByteString as B
3840import Data.Text.Encoding (decodeUtf8, encodeUtf8)
41+#else
42+import GHC.IO.Handle.Internals (wantWritableHandle)
43+#endif
3944
4045-- | The 'readFile' function reads a file and returns the contents of
4146-- the file as a string. The entire file is read strictly, as with
4247-- 'getContents'.
4348readFile :: FilePath -> IO Text
49+#if __GLASGOW_HASKELL__ <= 610
4450readFile = fmap decodeUtf8 . B.readFile
51+#else
52+readFile = undefined
53+#endif
4554
4655-- | Write a string to a file. The file is truncated to zero length
4756-- before writing begins.
4857writeFile :: FilePath -> Text -> IO ()
58+#if __GLASGOW_HASKELL__ <= 610
4959writeFile p = B.writeFile p . encodeUtf8
60+#else
61+writeFile = undefined
62+#endif
5063
5164-- | Write a string the end of a file.
5265appendFile :: FilePath -> Text -> IO ()
66+#if __GLASGOW_HASKELL__ <= 610
5367appendFile p = B.appendFile p . encodeUtf8
68+#else
69+appendFile = undefined
70+#endif
5471
5572-- | Read the remaining contents of a handle as a string.
5673hGetContents :: Handle -> IO Text
74+#if __GLASGOW_HASKELL__ <= 610
5775hGetContents = fmap decodeUtf8 . B.hGetContents
76+#else
77+hGetContents = undefined
78+#endif
5879
5980-- | Read a single line from a handle.
6081hGetLine :: Handle -> IO Text
82+#if __GLASGOW_HASKELL__ <= 610
6183hGetLine = fmap decodeUtf8 . B.hGetLine
84+#else
85+hGetLine = undefined
86+#endif
6287
6388-- | Write a string to a handle.
6489hPutStr :: Handle -> Text -> IO ()
90+#if __GLASGOW_HASKELL__ <= 610
6591hPutStr h = B.hPutStr h . encodeUtf8
92+#else
93+hPutStr h t = undefined
94+#endif
6695
6796-- | Write a string to a handle, followed by a newline.
6897hPutStrLn :: Handle -> Text -> IO ()
98+#if __GLASGOW_HASKELL__ <= 610
6999hPutStrLn h t = B.hPutStrLn h (encodeUtf8 t) >> hPutChar h '\n'
100+#else
101+hPutStrLn h t = undefined
102+#endif
70103
71104-- | The 'interact' function takes a function of type @Text -> Text@
72105-- as its argument. The entire input from the standard input device is
73106-- passed to this function as its argument, and the resulting string
74107-- is output on the standard output device.
75108interact :: (Text -> Text) -> IO ()
109+#if __GLASGOW_HASKELL__ <= 610
76110interact f = B.interact (encodeUtf8 . f . decodeUtf8)
111+#else
112+interact f = undefined
113+#endif
77114
78115-- | Read all user input on 'stdin' as a single string.
79116getContents :: IO Text