on master help sign in
Trim down the number of functions that need 6.12-specific implementations.
e2ad6abBryan O'Sullivan
Data/Text/IO.hs+4−19
@@ -48,34 +48,23 @@ import GHC.IO.Handle.Internals (wantWritableHandle)
48import GHC.IO.Handle.Text (commitBuffer')
48import GHC.IO.Handle.Text (commitBuffer')
49import GHC.IO.Handle.Types (BufferList(..), BufferMode(..), Handle__(..),
49import GHC.IO.Handle.Types (BufferList(..), BufferMode(..), Handle__(..),
50 Newline(..))
50 Newline(..))
51+import System.IO (IOMode(..), openFile, withFile)
51#endif
52#endif
52
53
53-- | The 'readFile' function reads a file and returns the contents of
54-- | The 'readFile' function reads a file and returns the contents of
54-- the file as a string. The entire file is read strictly, as with
55-- the file as a string. The entire file is read strictly, as with
55-- 'getContents'.
56-- 'getContents'.
56readFile :: FilePath -> IO Text
57readFile :: FilePath -> IO Text
57−#if __GLASGOW_HASKELL__ <= 610
58+readFile name = openFile name ReadMode >>= hGetContents
58−readFile = fmap decodeUtf8 . B.readFile
59−#else
60−readFile = undefined
61−#endif
62
59
63-- | Write a string to a file. The file is truncated to zero length
60-- | Write a string to a file. The file is truncated to zero length
64-- before writing begins.
61-- before writing begins.
65writeFile :: FilePath -> Text -> IO ()
62writeFile :: FilePath -> Text -> IO ()
66−#if __GLASGOW_HASKELL__ <= 610
63+writeFile p = withFile p WriteMode . flip hPutStr
67−writeFile p = B.writeFile p . encodeUtf8
68−#else
69−writeFile = undefined
70−#endif
71
64
72-- | Write a string the end of a file.
65-- | Write a string the end of a file.
73appendFile :: FilePath -> Text -> IO ()
66appendFile :: FilePath -> Text -> IO ()
74−#if __GLASGOW_HASKELL__ <= 610
67+appendFile p = withFile p AppendMode . flip hPutStr
75−appendFile p = B.appendFile p . encodeUtf8
76−#else
77−appendFile = undefined
78−#endif
79
68
80-- | Read the remaining contents of a handle as a string.
69-- | Read the remaining contents of a handle as a string.
81hGetContents :: Handle -> IO Text
70hGetContents :: Handle -> IO Text
@@ -174,11 +163,7 @@ commitBuffer hdl !raw !sz !count flush release =
174
163
175-- | Write a string to a handle, followed by a newline.
164-- | Write a string to a handle, followed by a newline.
176hPutStrLn :: Handle -> Text -> IO ()
165hPutStrLn :: Handle -> Text -> IO ()
177−#if __GLASGOW_HASKELL__ <= 610
178−hPutStrLn h t = B.hPutStrLn h (encodeUtf8 t) >> hPutChar h '\n'
179−#else
180hPutStrLn h t = hPutStr h t >> hPutChar h '\n'
166hPutStrLn h t = hPutStr h t >> hPutChar h '\n'
181−#endif
182
167
183-- | The 'interact' function takes a function of type @Text -> Text@
168-- | The 'interact' function takes a function of type @Text -> Text@
184-- as its argument. The entire input from the standard input device is
169-- as its argument. The entire input from the standard input device is