[Prev] [Up] [Next]


Text Input "PreludeReadTextIO"

This module defines the standard set of input operations for reading characters and strings from text files, using handles.

> interface PreludeReadTextIO where

> import PreludeMonadicIO
> import PreludeIOError
> import PreludeStdIO

Checking for Input

> hReady        :: Handle -> IO Bool 

Computation hReady hdl indicates whether at least one item is available for input from handle hdl. (Rationale)

The computation may fail with:

Reading Characters

> getChar       ::           IO Char
> hGetChar      :: Handle -> IO Char
> getChar       =  hGetChar stdin

Computation hGetChar hdl reads the next character from handle hdl, blocking until a character is available.

The computation may fail with:

getChar reads the next character from stdin. The computation may fail with the same errors as hGetChar.

Reading Ahead

> hLookAhead    :: Handle -> IO Char

Computation hLookAhead hdl returns the next character from handle hdl without removing it from the input buffer, blocking until a character is available. (Rationale)

The computation may fail with:

> hGetContents  :: Handle -> IO String

Computation hGetContents hdl returns the list of characters corresponding to the unread portion of the channel or file managed by hdl, which is made semi-closed.

The computation may fail with:

> readFile      :: FilePath -> IO String
> readFile name =  openFile name ReadMode >>= hGetContents

readFile file returns the contents of file as a lazy string.

The computation may fail with:


[Prev] [Up] [Next]


The Definition of Monadic I/O in Haskell 1.3
Haskell 1.3 Committee
haskell1.3@comp.vuw.ac.nz