text-0.10.0.0: An efficient packed Unicode text type.Source codeContentsIndex
Data.Text.Lazy.IO
PortabilityGHC
Stabilityexperimental
Maintainerbos@serpentine.com
Contents
Locale support
Operations on handles
Special cases for standard input and output
Description
Efficient locale-sensitive support for lazy text I/O.
Synopsis
readFile :: FilePath -> IO Text
writeFile :: FilePath -> Text -> IO ()
appendFile :: FilePath -> Text -> IO ()
hGetContents :: Handle -> IO Text
hGetLine :: Handle -> IO Text
hPutStr :: Handle -> Text -> IO ()
hPutStrLn :: Handle -> Text -> IO ()
interact :: (Text -> Text) -> IO ()
getContents :: IO Text
getLine :: IO Text
putStr :: Text -> IO ()
putStrLn :: Text -> IO ()
Locale support

Note: The behaviour of functions in this module depends on the version of GHC you are using.

Beginning with GHC 6.12, text I/O is performed using the system or handle's current locale and line ending conventions.

Under GHC 6.10 and earlier, the system I/O libraries /do not support locale-sensitive I\O or line ending conversion. On these versions of GHC, functions in this library all use UTF-8. What does this mean in practice?

  • All data that is read will be decoded as UTF-8.
  • Before data is written, it is first encoded as UTF-8.
  • On both reading and writing, the platform's native newline conversion is performed.

If you must use a non-UTF-8 locale on an older version of GHC, you will have to perform the transcoding yourself, e.g. as follows:

 import qualified Data.ByteString.Lazy as B
 import Data.Text.Lazy (Text)
 import Data.Text.Lazy.Encoding (encodeUtf16)

 putStr_Utf16LE :: Text -> IO ()
 putStr_Utf16LE t = B.putStr (encodeUtf16LE t)
readFile :: FilePath -> IO TextSource
Read a file and return its contents as a string. The file is read lazily, as with getContents.
writeFile :: FilePath -> Text -> IO ()Source
Write a string to a file. The file is truncated to zero length before writing begins.
appendFile :: FilePath -> Text -> IO ()Source
Write a string the end of a file.
Operations on handles
hGetContents :: Handle -> IO TextSource
Lazily read the remaining contents of a Handle. The Handle will be closed after the read completes, or on error.
hGetLine :: Handle -> IO TextSource
Read a single line from a handle.
hPutStr :: Handle -> Text -> IO ()Source
Write a string to a handle.
hPutStrLn :: Handle -> Text -> IO ()Source
Write a string to a handle, followed by a newline.
Special cases for standard input and output
interact :: (Text -> Text) -> IO ()Source
The interact function takes a function of type Text -> Text as its argument. The entire input from the standard input device is passed (lazily) to this function as its argument, and the resulting string is output on the standard output device.
getContents :: IO TextSource
Lazily read all user input on stdin as a single string.
getLine :: IO TextSource
Read a single line of user input from stdin.
putStr :: Text -> IO ()Source
Write a string to stdout.
putStrLn :: Text -> IO ()Source
Write a string to stdout, followed by a newline.
Produced by Haddock version 2.6.1