Community
Modules 50

Data.Text.Lazy.IO

Efficient locale-sensitive support for lazy text I/O.

The functions in this module obey the runtime system's locale, character set encoding, and line ending conversion settings.

If you know in advance that you will be working with data that has a specific encoding (e.g. UTF-8), and your application is highly performance sensitive, you may find that it is faster to perform I/O with bytestrings and to encode and decode yourself than to use the functions in this module.

File-at-a-time operations

readFile :: FilePath -> IO Text

Read a file and return its contents as a string. The file is read lazily, as with getContents.

Beware that this function (similarly to readFile) is locale-dependent. Unexpected system locale may cause your application to read corrupted data or throw runtime exceptions about "invalid argument (invalid byte sequence)" or "invalid argument (invalid character)". This is also slow, because GHC first converts an entire input to UTF-32, which is afterwards converted to UTF-8.

If your data is UTF-8, using decodeUtf8 . readFile is a much faster and safer alternative.

writeFile :: FilePath -> Text -> IO ()

Write a string to a file. The file is truncated to zero length before writing begins.

appendFile :: FilePath -> Text -> IO ()

Write a string to the end of a file.

Operations on handles

hGetContents :: Handle -> IO Text

Lazily read the remaining contents of a Handle. The Handle will be closed after the read completes, or on error.

hGetLine :: Handle -> IO Text

Read a single line from a handle.

hPutStr :: Handle -> Text -> IO ()

Write a string to a handle.

hPutStrLn :: Handle -> Text -> IO ()

Write a string to a handle, followed by a newline.

Special cases for standard input and output

interact :: (Text -> Text) -> IO ()

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 Text

Lazily read all user input on stdin as a single string.

getLine :: IO Text

Read a single line of user input from stdin.

putStr :: Text -> IO ()

Write a string to stdout.

putStrLn :: Text -> IO ()

Write a string to stdout, followed by a newline.

Maintainer
bos@serpentine.com
Portability
GHC
Copyright
(c) 2009, 2010 Bryan O'Sullivan, (c) 2009 Simon Marlow
License
BSD-style
Build record and source files

Community contribution. The service has not verified this documentation. The generator reported 2 diagnostics.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-858b1951-web-1

Metadata snapshot: 0b0724abd14577f7a6c8172d62e3e1c0808feb114d4d379402e17f37e3c7801e

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.