[Prev] [Up] [Next]


Text Output "PreludeWriteTextIO"

This module defines the standard set of output operations for writing characters and strings to text files, using handles.


> interface PreludeWriteTextIO where

> import PreludeMonadicIO
> import PreludeIOError
> import PreludeStdIO

> putChar       ::                     Char   -> IO () 
> hPutChar      ::           Handle -> Char   -> IO ()
> putChar       =  hPutChar stdout

Computation hPutChar hdl c writes the character c to the file or channel managed by hdl. Characters may be buffered if buffering is enabled for hdl.

The computation may fail with:

> putStr        ::                     String -> IO () 
> hPutStr       ::           Handle -> String -> IO ()
> putText       :: Text a =>           a      -> IO () 
> hPutText      :: Text a => Handle -> a      -> IO ()
> print         :: Text a =>           a      -> IO ()

> putStr        =  hPutStr stdout
> hPutStr hdl   =  foldr (>>) (return ()) . map (hPutChar hdl)
> putText       =  hPutText stdout
> hPutText hdl  =  hPutStr hdl . show
> print x       =  putText x >> putChar '\n'

Computation hPutStr hdl s writes the string s to the file or channel managed by hdl.

The computation may fail with:

Computation putStr s writes the string s to stdout. The computation may fail with the same errors as hPutChar.

Computation hPutText hdl t writes the string representation of t given by the shows function to the file or channel managed by hdl.

The computation may fail with the same errors as hPutStr.

> writeFile  :: FilePath -> String -> IO ()
> appendFile :: FilePath -> String -> IO ()

> writeFile name str =
>   openFile name WriteMode >>= \hdl -> hPutStr hdl str >> hClose hdl

> appendFile name str =
>   openFile name AppendMode >>= \hdl -> hPutStr hdl str >> hClose hdl

writeFile file s replaces the contents of file by the string s.
appendFile file s appends string s to file.

These computations 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