| |||||||||
| |||||||||
Synopsis | |||||||||
Documentation | |||||||||
data Handle | |||||||||
| |||||||||
HandlePosn | |||||||||
IOMode | |||||||||
data BufferMode | |||||||||
| |||||||||
SeekMode | |||||||||
stdin | |||||||||
stdout | |||||||||
stderr | |||||||||
openFile | |||||||||
hClose | |||||||||
hFileSize | |||||||||
hIsEOF | |||||||||
isEOF | |||||||||
hSetBuffering | |||||||||
hGetBuffering | |||||||||
hFlush | |||||||||
hGetPosn | |||||||||
hSetPosn | |||||||||
hSeek | |||||||||
hWaitForInput | |||||||||
hReady :: Handle -> IO Bool | |||||||||
Computation hReady hdl indicates whether at least one item is available for input from handle hdl. This operation may fail with:
| |||||||||
hGetChar | |||||||||
hGetLine | |||||||||
hLookAhead | |||||||||
hGetContents | |||||||||
hPutChar | |||||||||
hPutStr | |||||||||
hPutStrLn :: Handle -> String -> IO () | |||||||||
The same as hPutStr, but adds a newline character. | |||||||||
hPrint :: Show a => Handle -> a -> IO () | |||||||||
Computation hPrint hdl t writes the string representation of t given by the shows function to the file or channel managed by hdl and appends a newline. This operation may fail with:
| |||||||||
hIsOpen | |||||||||
hIsClosed | |||||||||
hIsReadable | |||||||||
hIsWritable | |||||||||
hIsSeekable | |||||||||
isAlreadyExistsError :: IOError -> Bool | |||||||||
An error indicating that an IO operation failed because one of its arguments already exists. | |||||||||
isDoesNotExistError :: IOError -> Bool | |||||||||
An error indicating that an IO operation failed because one of its arguments does not exist. | |||||||||
isAlreadyInUseError :: IOError -> Bool | |||||||||
An error indicating that an IO operation failed because one of its arguments is a single-use resource, which is already being used (for example, opening the same file twice for writing might give this error). | |||||||||
isFullError :: IOError -> Bool | |||||||||
An error indicating that an IO operation failed because the device is full. | |||||||||
isEOFError :: IOError -> Bool | |||||||||
An error indicating that an IO operation failed because the end of file has been reached. | |||||||||
isIllegalOperation :: IOError -> Bool | |||||||||
An error indicating that an IO operation failed because the operation was not possible. Any computation which returns an IO result may fail with isIllegalOperation. In some cases, an implementation will not be able to distinguish between the possible error causes. In this case it should fail with isIllegalOperation. | |||||||||
isPermissionError :: IOError -> Bool | |||||||||
An error indicating that an IO operation failed because the user does not have sufficient operating system privilege to perform that operation. | |||||||||
isUserError :: IOError -> Bool | |||||||||
A programmer-defined error value constructed using userError. | |||||||||
ioeGetErrorString :: IOError -> String | |||||||||
ioeGetHandle :: IOError -> Maybe Handle | |||||||||
ioeGetFileName :: IOError -> Maybe FilePath | |||||||||
try :: IO a -> IO (Either IOError a) | |||||||||
The construct try comp exposes IO errors which occur within a computation, and which are not fully handled. Non-I/O exceptions are not caught by this variant; to catch all exceptions, use Control.Exception.try from Control.Exception. | |||||||||
bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c | |||||||||
The bracket function captures a common allocate, compute, deallocate idiom in which the deallocation step must occur even in the case of an error during computation. This is similar to try-catch-finally in Java. This version handles only IO errors, as defined by Haskell 98. The version of bracket in Control.Exception handles all exceptions, and should be used instead. | |||||||||
bracket_ :: IO a -> (a -> IO b) -> IO c -> IO c | |||||||||
A variant of bracket where the middle computation doesn't want x. This version handles only IO errors, as defined by Haskell 98. The version of bracket_ in Control.Exception handles all exceptions, and should be used instead. | |||||||||
data IO a | |||||||||
| |||||||||
type FilePath = String | |||||||||
File and directory names are values of type String, whose precise meaning is operating system dependent. Files can be opened, yielding a handle which can then be used to operate on the contents of that file. | |||||||||
type IOError = IOException | |||||||||
The Haskell 98 type for exceptions in the IO monad. Any I/O operation may raise an IOError instead of returning a result. For a more general type of exception, including also those that arise in pure code, see Control.Exception.Exception. In Haskell 98, this is an opaque type. | |||||||||
ioError :: IOError -> IO a | |||||||||
Raise an IOError in the IO monad. | |||||||||
userError :: String -> IOError | |||||||||
Construct an IOError value with a string describing the error. The fail method of the IO instance of the Monad class raises a userError, thus: instance Monad IO where ... fail s = ioError (userError s) | |||||||||
catch :: IO a -> (IOError -> IO a) -> IO a | |||||||||
The catch function establishes a handler that receives any IOError raised in the action protected by catch. An IOError is caught by the most recent handler established by catch. These handlers are not selective: all IOErrors are caught. Exception propagation must be explicitly provided in a handler by re-raising any unwanted exceptions. For example, in f = catch g (\e -> if IO.isEOFError e then return [] else ioError e)the function f returns [] when an end-of-file exception (cf. isEOFError) occurs in g; otherwise, the exception is propagated to the next outer handler. When an exception propagates outside the main program, the Haskell system prints the associated IOError value and exits the program. Non-I/O exceptions are not caught by this variant; to catch all exceptions, use Control.Exception.catch from Control.Exception. | |||||||||
interact :: (String -> String) -> IO () | |||||||||
The interact function takes a function of type String->String 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. | |||||||||
putChar :: Char -> IO () | |||||||||
Write a character to the standard output device (same as hPutChar stdout). | |||||||||
putStr :: String -> IO () | |||||||||
Write a string to the standard output device (same as hPutStr stdout). | |||||||||
putStrLn :: String -> IO () | |||||||||
The same as putStr, but adds a newline character. | |||||||||
print :: Show a => a -> IO () | |||||||||
The print function outputs a value of any printable type to the standard output device. Printable types are those that are instances of class Show; print converts values to strings for output using the show operation and adds a newline. For example, a program to print the first 20 integers and their powers of 2 could be written as: main = print ([(n, 2^n) | n <- [0..19]]) | |||||||||
getChar :: IO Char | |||||||||
Read a character from the standard input device (same as hGetChar stdin). | |||||||||
getLine :: IO String | |||||||||
Read a line from the standard input device (same as hGetLine stdin). | |||||||||
getContents :: IO String | |||||||||
The getContents operation returns all user input as a single string, which is read lazily as it is needed (same as hGetContents stdin). | |||||||||
readFile :: FilePath -> IO String | |||||||||
The readFile function reads a file and returns the contents of the file as a string. The file is read lazily, on demand, as with getContents. | |||||||||
writeFile :: FilePath -> String -> IO () | |||||||||
The computation writeFile file str function writes the string str, to the file file. | |||||||||
appendFile :: FilePath -> String -> IO () | |||||||||
The computation appendFile file str function appends the string str, to the file file. Note that writeFile and appendFile write a literal string to a file. To write a value of any printable type, as with print, use the show function to convert the value to a string first. main = appendFile "squares" (show [(x,x*x) | x <- [0,0.1..2]]) | |||||||||
readIO :: Read a => String -> IO a | |||||||||
The readIO function is similar to read except that it signals parse failure to the IO monad instead of terminating the program. | |||||||||
readLn :: Read a => IO a | |||||||||
The readLn function combines getLine and readIO. | |||||||||
Produced by Haddock version 2.6.0 |