<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>IO</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_IO.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">haskell98-2.0.0.1: Compatibility with Haskell 98</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>Safe</td></tr></table><p class="caption">IO</p></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">data</span> <a href="#t:Handle">Handle</a> </li><li class="src short"><span class="keyword">data</span> <a href="#t:HandlePosn">HandlePosn</a> </li><li class="src short"><span class="keyword">data</span> <a href="#t:IOMode">IOMode</a> <ul class="subs"><li>= <a href="#v:ReadMode">ReadMode</a> </li><li>| <a href="#v:WriteMode">WriteMode</a> </li><li>| <a href="#v:AppendMode">AppendMode</a> </li><li>| <a href="#v:ReadWriteMode">ReadWriteMode</a> </li></ul></li><li class="src short"><span class="keyword">data</span> <a href="#t:BufferMode">BufferMode</a> <ul class="subs"><li>= <a href="#v:NoBuffering">NoBuffering</a> </li><li>| <a href="#v:LineBuffering">LineBuffering</a> </li><li>| <a href="#v:BlockBuffering">BlockBuffering</a> (<a href="Prelude.html#t:Maybe">Maybe</a> <a href="Prelude.html#t:Int">Int</a>) </li></ul></li><li class="src short"><span class="keyword">data</span> <a href="#t:SeekMode">SeekMode</a> <ul class="subs"><li>= <a href="#v:AbsoluteSeek">AbsoluteSeek</a> </li><li>| <a href="#v:RelativeSeek">RelativeSeek</a> </li><li>| <a href="#v:SeekFromEnd">SeekFromEnd</a> </li></ul></li><li class="src short"><a href="#v:stdin">stdin</a> :: <a href="IO.html#t:Handle">Handle</a></li><li class="src short"><a href="#v:stdout">stdout</a> :: <a href="IO.html#t:Handle">Handle</a></li><li class="src short"><a href="#v:stderr">stderr</a> :: <a href="IO.html#t:Handle">Handle</a></li><li class="src short"><a href="#v:openFile">openFile</a> :: <a href="IO.html#t:FilePath">FilePath</a> -> <a href="IO.html#t:IOMode">IOMode</a> -> <a href="IO.html#t:IO">IO</a> <a href="IO.html#t:Handle">Handle</a></li><li class="src short"><a href="#v:hClose">hClose</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hFileSize">hFileSize</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Integer">Integer</a></li><li class="src short"><a href="#v:hIsEOF">hIsEOF</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isEOF">isEOF</a> :: <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hSetBuffering">hSetBuffering</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:BufferMode">BufferMode</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hGetBuffering">hGetBuffering</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="IO.html#t:BufferMode">BufferMode</a></li><li class="src short"><a href="#v:hFlush">hFlush</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hGetPosn">hGetPosn</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="IO.html#t:HandlePosn">HandlePosn</a></li><li class="src short"><a href="#v:hSetPosn">hSetPosn</a> :: <a href="IO.html#t:HandlePosn">HandlePosn</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hSeek">hSeek</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:SeekMode">SeekMode</a> -> <a href="Prelude.html#t:Integer">Integer</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hWaitForInput">hWaitForInput</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:Int">Int</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hReady">hReady</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hGetChar">hGetChar</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Char">Char</a></li><li class="src short"><a href="#v:hGetLine">hGetLine</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:String">String</a></li><li class="src short"><a href="#v:hLookAhead">hLookAhead</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Char">Char</a></li><li class="src short"><a href="#v:hGetContents">hGetContents</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:String">String</a></li><li class="src short"><a href="#v:hPutChar">hPutChar</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:Char">Char</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hPutStr">hPutStr</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hPutStrLn">hPutStrLn</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hPrint">hPrint</a> :: <a href="Prelude.html#t:Show">Show</a> a => <a href="IO.html#t:Handle">Handle</a> -> a -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hIsOpen">hIsOpen</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hIsClosed">hIsClosed</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hIsReadable">hIsReadable</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hIsWritable">hIsWritable</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hIsSeekable">hIsSeekable</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isAlreadyExistsError">isAlreadyExistsError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isDoesNotExistError">isDoesNotExistError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isAlreadyInUseError">isAlreadyInUseError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isFullError">isFullError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isEOFError">isEOFError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isIllegalOperation">isIllegalOperation</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isPermissionError">isPermissionError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isUserError">isUserError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:ioeGetErrorString">ioeGetErrorString</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:String">String</a></li><li class="src short"><a href="#v:ioeGetHandle">ioeGetHandle</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="IO.html#t:Handle">Handle</a></li><li class="src short"><a href="#v:ioeGetFileName">ioeGetFileName</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="IO.html#t:FilePath">FilePath</a></li><li class="src short"><a href="#v:try">try</a> :: <a href="IO.html#t:IO">IO</a> a -> <a href="IO.html#t:IO">IO</a> (<a href="Prelude.html#t:Either">Either</a> <a href="IO.html#t:IOError">IOError</a> a)</li><li class="src short"><a href="#v:bracket">bracket</a> :: <a href="IO.html#t:IO">IO</a> a -> (a -> <a href="IO.html#t:IO">IO</a> b) -> (a -> <a href="IO.html#t:IO">IO</a> c) -> <a href="IO.html#t:IO">IO</a> c</li><li class="src short"><a href="#v:bracket_">bracket_</a> :: <a href="IO.html#t:IO">IO</a> a -> (a -> <a href="IO.html#t:IO">IO</a> b) -> <a href="IO.html#t:IO">IO</a> c -> <a href="IO.html#t:IO">IO</a> c</li><li class="src short"><span class="keyword">data</span> <a href="#t:IO">IO</a> a</li><li class="src short"><span class="keyword">type</span> <a href="#t:FilePath">FilePath</a> = <a href="Prelude.html#t:String">String</a></li><li class="src short"><span class="keyword">type</span> <a href="#t:IOError">IOError</a> = <a href="../base-4.5.1.0/Control-Exception-Base.html#t:IOException">IOException</a></li><li class="src short"><a href="#v:ioError">ioError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:userError">userError</a> :: <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IOError">IOError</a></li><li class="src short"><a href="#v:catch">catch</a> :: <a href="IO.html#t:IO">IO</a> a -> (<a href="IO.html#t:IOError">IOError</a> -> <a href="IO.html#t:IO">IO</a> a) -> <a href="IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:interact">interact</a> :: (<a href="Prelude.html#t:String">String</a> -> <a href="Prelude.html#t:String">String</a>) -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:putChar">putChar</a> :: <a href="Prelude.html#t:Char">Char</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:putStr">putStr</a> :: <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:putStrLn">putStrLn</a> :: <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:print">print</a> :: <a href="Prelude.html#t:Show">Show</a> a => a -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:getChar">getChar</a> :: <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Char">Char</a></li><li class="src short"><a href="#v:getLine">getLine</a> :: <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:String">String</a></li><li class="src short"><a href="#v:getContents">getContents</a> :: <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:String">String</a></li><li class="src short"><a href="#v:readFile">readFile</a> :: <a href="IO.html#t:FilePath">FilePath</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:String">String</a></li><li class="src short"><a href="#v:writeFile">writeFile</a> :: <a href="IO.html#t:FilePath">FilePath</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:appendFile">appendFile</a> :: <a href="IO.html#t:FilePath">FilePath</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:readIO">readIO</a> :: <a href="Prelude.html#t:Read">Read</a> a => <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:readLn">readLn</a> :: <a href="Prelude.html#t:Read">Read</a> a => <a href="IO.html#t:IO">IO</a> a</li></ul></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:Handle" class="def">Handle</a> <a href="../base-4.5.1.0/src/GHC-IO-Handle-Types.html#Handle" class="link">Source</a></p><div class="doc"><p>Haskell defines operations to read and write characters from and to files, represented by values of type <code>Handle</code>. Each value of this type is a <em>handle</em>: a record used by the Haskell run-time system to <em>manage</em> I/O with file system objects. A handle has at least the following properties: </p><ul><li> whether it manages input or output or both; </li><li> whether it is <em>open</em>, <em>closed</em> or <em>semi-closed</em>; </li><li> whether the object is seekable; </li><li> whether buffering is disabled, or enabled on a line or block basis; </li><li> a buffer (whose length may be zero). </li></ul><p>Most handles will also have a current I/O position indicating where the next input or output operation will occur. A handle is <em>readable</em> if it manages only input or both input and output; likewise, it is <em>writable</em> if it manages only output or both input and output. A handle is <em>open</em> when first allocated. Once it is closed it can no longer be used for either input or output, though an implementation cannot re-use its storage while references remain to it. Handles are in the <code><a href="Prelude.html#t:Show">Show</a></code> and <code><a href="Prelude.html#t:Eq">Eq</a></code> classes. The string produced by showing a handle is system dependent; it should include enough information to identify the handle for debugging. A handle is equal according to <code><a href="Prelude.html#v:-61--61-">==</a></code> only to itself; no attempt is made to compare the internal state of different handles for equality. </p></div><div class="subs instances"><p id="control.i:Handle" class="caption collapser" onclick="toggleSection('i:Handle')">Instances</p><div id="section.i:Handle" class="show"><table><tr><td class="src"><a href="Prelude.html#t:Eq">Eq</a> <a href="IO.html#t:Handle">Handle</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Show">Show</a> <a href="IO.html#t:Handle">Handle</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="../base-4.5.1.0/Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="IO.html#t:Handle">Handle</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:HandlePosn" class="def">HandlePosn</a> <a href="../base-4.5.1.0/src/GHC-IO-Handle.html#HandlePosn" class="link">Source</a></p><div class="subs instances"><p id="control.i:HandlePosn" class="caption collapser" onclick="toggleSection('i:HandlePosn')">Instances</p><div id="section.i:HandlePosn" class="show"><table><tr><td class="src"><a href="Prelude.html#t:Eq">Eq</a> <a href="IO.html#t:HandlePosn">HandlePosn</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Show">Show</a> <a href="IO.html#t:HandlePosn">HandlePosn</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:IOMode" class="def">IOMode</a> <a href="../base-4.5.1.0/src/GHC-IO-IOMode.html#IOMode" class="link">Source</a></p><div class="doc"><p>See <code><a href="../base-4.5.1.0/System-IO.html#v:openFile">openFile</a></code> </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:ReadMode" class="def">ReadMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a name="v:WriteMode" class="def">WriteMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a name="v:AppendMode" class="def">AppendMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a name="v:ReadWriteMode" class="def">ReadWriteMode</a></td><td class="doc empty"> </td></tr></table></div><div class="subs instances"><p id="control.i:IOMode" class="caption collapser" onclick="toggleSection('i:IOMode')">Instances</p><div id="section.i:IOMode" class="show"><table><tr><td class="src"><a href="Prelude.html#t:Enum">Enum</a> <a href="IO.html#t:IOMode">IOMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Eq">Eq</a> <a href="IO.html#t:IOMode">IOMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Ord">Ord</a> <a href="IO.html#t:IOMode">IOMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Read">Read</a> <a href="IO.html#t:IOMode">IOMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Show">Show</a> <a href="IO.html#t:IOMode">IOMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Ix.html#t:Ix">Ix</a> <a href="IO.html#t:IOMode">IOMode</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:BufferMode" class="def">BufferMode</a> <a href="../base-4.5.1.0/src/GHC-IO-Handle-Types.html#BufferMode" class="link">Source</a></p><div class="doc"><p>Three kinds of buffering are supported: line-buffering, block-buffering or no-buffering. These modes have the following effects. For output, items are written out, or <em>flushed</em>, from the internal buffer according to the buffer mode: </p><ul><li> <em>line-buffering</em>: the entire output buffer is flushed whenever a newline is output, the buffer overflows, a <code><a href="../base-4.5.1.0/System-IO.html#v:hFlush">hFlush</a></code> is issued, or the handle is closed. </li><li> <em>block-buffering</em>: the entire buffer is written out whenever it overflows, a <code><a href="../base-4.5.1.0/System-IO.html#v:hFlush">hFlush</a></code> is issued, or the handle is closed. </li><li> <em>no-buffering</em>: output is written immediately, and never stored in the buffer. </li></ul><p>An implementation is free to flush the buffer more frequently, but not less frequently, than specified above. The output buffer is emptied as soon as it has been written out. </p><p>Similarly, input occurs according to the buffer mode for the handle: </p><ul><li> <em>line-buffering</em>: when the buffer for the handle is not empty, the next item is obtained from the buffer; otherwise, when the buffer is empty, characters up to and including the next newline character are read into the buffer. No characters are available until the newline character is available or the buffer is full. </li><li> <em>block-buffering</em>: when the buffer for the handle becomes empty, the next block of data is read into the buffer. </li><li> <em>no-buffering</em>: the next input item is read and returned. The <code><a href="../base-4.5.1.0/System-IO.html#v:hLookAhead">hLookAhead</a></code> operation implies that even a no-buffered handle may require a one-character buffer. </li></ul><p>The default buffering mode when a handle is opened is implementation-dependent and may depend on the file system object which is attached to that handle. For most implementations, physical files will normally be block-buffered and terminals will normally be line-buffered. </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:NoBuffering" class="def">NoBuffering</a></td><td class="doc"><p>buffering is disabled if possible. </p></td></tr><tr><td class="src"><a name="v:LineBuffering" class="def">LineBuffering</a></td><td class="doc"><p>line-buffering should be enabled if possible. </p></td></tr><tr><td class="src"><a name="v:BlockBuffering" class="def">BlockBuffering</a> (<a href="Prelude.html#t:Maybe">Maybe</a> <a href="Prelude.html#t:Int">Int</a>)</td><td class="doc"><p>block-buffering should be enabled if possible. The size of the buffer is <code>n</code> items if the argument is <code><a href="Prelude.html#v:Just">Just</a></code> <code>n</code> and is otherwise implementation-dependent. </p></td></tr></table></div><div class="subs instances"><p id="control.i:BufferMode" class="caption collapser" onclick="toggleSection('i:BufferMode')">Instances</p><div id="section.i:BufferMode" class="show"><table><tr><td class="src"><a href="Prelude.html#t:Eq">Eq</a> <a href="IO.html#t:BufferMode">BufferMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Ord">Ord</a> <a href="IO.html#t:BufferMode">BufferMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Read">Read</a> <a href="IO.html#t:BufferMode">BufferMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Show">Show</a> <a href="IO.html#t:BufferMode">BufferMode</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:SeekMode" class="def">SeekMode</a> <a href="../base-4.5.1.0/src/GHC-IO-Device.html#SeekMode" class="link">Source</a></p><div class="doc"><p>A mode that determines the effect of <code>hSeek</code> <code>hdl mode i</code>. </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:AbsoluteSeek" class="def">AbsoluteSeek</a></td><td class="doc"><p>the position of <code>hdl</code> is set to <code>i</code>. </p></td></tr><tr><td class="src"><a name="v:RelativeSeek" class="def">RelativeSeek</a></td><td class="doc"><p>the position of <code>hdl</code> is set to offset <code>i</code> from the current position. </p></td></tr><tr><td class="src"><a name="v:SeekFromEnd" class="def">SeekFromEnd</a></td><td class="doc"><p>the position of <code>hdl</code> is set to offset <code>i</code> from the end of the file. </p></td></tr></table></div><div class="subs instances"><p id="control.i:SeekMode" class="caption collapser" onclick="toggleSection('i:SeekMode')">Instances</p><div id="section.i:SeekMode" class="show"><table><tr><td class="src"><a href="Prelude.html#t:Enum">Enum</a> <a href="IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Eq">Eq</a> <a href="IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Ord">Ord</a> <a href="IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Read">Read</a> <a href="IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Show">Show</a> <a href="IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Ix.html#t:Ix">Ix</a> <a href="IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:stdin" class="def">stdin</a> :: <a href="IO.html#t:Handle">Handle</a><a href="../base-4.5.1.0/src/GHC-IO-Handle-FD.html#stdin" class="link">Source</a></p><div class="doc"><p>A handle managing input from the Haskell program's standard input channel. </p></div></div><div class="top"><p class="src"><a name="v:stdout" class="def">stdout</a> :: <a href="IO.html#t:Handle">Handle</a><a href="../base-4.5.1.0/src/GHC-IO-Handle-FD.html#stdout" class="link">Source</a></p><div class="doc"><p>A handle managing output to the Haskell program's standard output channel. </p></div></div><div class="top"><p class="src"><a name="v:stderr" class="def">stderr</a> :: <a href="IO.html#t:Handle">Handle</a><a href="../base-4.5.1.0/src/GHC-IO-Handle-FD.html#stderr" class="link">Source</a></p><div class="doc"><p>A handle managing output to the Haskell program's standard error channel. </p></div></div><div class="top"><p class="src"><a name="v:openFile" class="def">openFile</a> :: <a href="IO.html#t:FilePath">FilePath</a> -> <a href="IO.html#t:IOMode">IOMode</a> -> <a href="IO.html#t:IO">IO</a> <a href="IO.html#t:Handle">Handle</a><a href="../base-4.5.1.0/src/GHC-IO-Handle-FD.html#openFile" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:openFile">openFile</a></code> <code>file mode</code> allocates and returns a new, open handle to manage the file <code>file</code>. It manages input if <code>mode</code> is <code><a href="IO.html#v:ReadMode">ReadMode</a></code>, output if <code>mode</code> is <code><a href="IO.html#v:WriteMode">WriteMode</a></code> or <code><a href="IO.html#v:AppendMode">AppendMode</a></code>, and both input and output if mode is <code><a href="IO.html#v:ReadWriteMode">ReadWriteMode</a></code>. </p><p>If the file does not exist and it is opened for output, it should be created as a new file. If <code>mode</code> is <code><a href="IO.html#v:WriteMode">WriteMode</a></code> and the file already exists, then it should be truncated to zero length. Some operating systems delete empty files, so there is no guarantee that the file will exist following an <code><a href="IO.html#v:openFile">openFile</a></code> with <code>mode</code> <code><a href="IO.html#v:WriteMode">WriteMode</a></code> unless it is subsequently written to successfully. The handle is positioned at the end of the file if <code>mode</code> is <code><a href="IO.html#v:AppendMode">AppendMode</a></code>, and otherwise at the beginning (in which case its internal position is 0). The initial buffer mode is implementation-dependent. </p><p>This operation may fail with: </p><ul><li> <code>isAlreadyInUseError</code> if the file is already open and cannot be reopened; </li><li> <code>isDoesNotExistError</code> if the file does not exist; or </li><li> <code>isPermissionError</code> if the user does not have permission to open the file. </li></ul><p>Note: if you will be working with files containing binary data, you'll want to be using <code><a href="../base-4.5.1.0/GHC-IO-Handle-FD.html#v:openBinaryFile">openBinaryFile</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:hClose" class="def">hClose</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hClose" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hClose">hClose</a></code> <code>hdl</code> makes handle <code>hdl</code> closed. Before the computation finishes, if <code>hdl</code> is writable its buffer is flushed as for <code><a href="IO.html#v:hFlush">hFlush</a></code>. Performing <code><a href="IO.html#v:hClose">hClose</a></code> on a handle that has already been closed has no effect; doing so is not an error. All other operations on a closed handle will fail. If <code><a href="IO.html#v:hClose">hClose</a></code> fails for any reason, any further operations (apart from <code><a href="IO.html#v:hClose">hClose</a></code>) on the handle will still fail as if <code>hdl</code> had been successfully closed. </p></div></div><div class="top"><p class="src"><a name="v:hFileSize" class="def">hFileSize</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Integer">Integer</a><a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hFileSize" class="link">Source</a></p><div class="doc"><p>For a handle <code>hdl</code> which attached to a physical file, <code><a href="IO.html#v:hFileSize">hFileSize</a></code> <code>hdl</code> returns the size of that file in 8-bit bytes. </p></div></div><div class="top"><p class="src"><a name="v:hIsEOF" class="def">hIsEOF</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hIsEOF" class="link">Source</a></p><div class="doc"><p>For a readable handle <code>hdl</code>, <code><a href="IO.html#v:hIsEOF">hIsEOF</a></code> <code>hdl</code> returns <code><a href="Prelude.html#v:True">True</a></code> if no further input can be taken from <code>hdl</code> or for a physical file, if the current I/O position is equal to the length of the file. Otherwise, it returns <code><a href="Prelude.html#v:False">False</a></code>. </p><p>NOTE: <code><a href="IO.html#v:hIsEOF">hIsEOF</a></code> may block, because it has to attempt to read from the stream to determine whether there is any more data to be read. </p></div></div><div class="top"><p class="src"><a name="v:isEOF" class="def">isEOF</a> :: <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/GHC-IO-Handle-FD.html#isEOF" class="link">Source</a></p><div class="doc"><p>The computation <code><a href="IO.html#v:isEOF">isEOF</a></code> is identical to <code><a href="IO.html#v:hIsEOF">hIsEOF</a></code>, except that it works only on <code><a href="IO.html#v:stdin">stdin</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:hSetBuffering" class="def">hSetBuffering</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:BufferMode">BufferMode</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hSetBuffering" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hSetBuffering">hSetBuffering</a></code> <code>hdl mode</code> sets the mode of buffering for handle <code>hdl</code> on subsequent reads and writes. </p><p>If the buffer mode is changed from <code><a href="IO.html#v:BlockBuffering">BlockBuffering</a></code> or <code><a href="IO.html#v:LineBuffering">LineBuffering</a></code> to <code><a href="IO.html#v:NoBuffering">NoBuffering</a></code>, then </p><ul><li> if <code>hdl</code> is writable, the buffer is flushed as for <code><a href="IO.html#v:hFlush">hFlush</a></code>; </li><li> if <code>hdl</code> is not writable, the contents of the buffer is discarded. </li></ul><p>This operation may fail with: </p><ul><li> <code>isPermissionError</code> if the handle has already been used for reading or writing and the implementation does not allow the buffering mode to be changed. </li></ul></div></div><div class="top"><p class="src"><a name="v:hGetBuffering" class="def">hGetBuffering</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="IO.html#t:BufferMode">BufferMode</a><a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hGetBuffering" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hGetBuffering">hGetBuffering</a></code> <code>hdl</code> returns the current buffering mode for <code>hdl</code>. </p></div></div><div class="top"><p class="src"><a name="v:hFlush" class="def">hFlush</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hFlush" class="link">Source</a></p><div class="doc"><p>The action <code><a href="IO.html#v:hFlush">hFlush</a></code> <code>hdl</code> causes any items buffered for output in handle <code>hdl</code> to be sent immediately to the operating system. </p><p>This operation may fail with: </p><ul><li> <code>isFullError</code> if the device is full; </li><li> <code>isPermissionError</code> if a system resource limit would be exceeded. It is unspecified whether the characters in the buffer are discarded or retained under these circumstances. </li></ul></div></div><div class="top"><p class="src"><a name="v:hGetPosn" class="def">hGetPosn</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="IO.html#t:HandlePosn">HandlePosn</a><a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hGetPosn" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hGetPosn">hGetPosn</a></code> <code>hdl</code> returns the current I/O position of <code>hdl</code> as a value of the abstract type <code><a href="IO.html#t:HandlePosn">HandlePosn</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:hSetPosn" class="def">hSetPosn</a> :: <a href="IO.html#t:HandlePosn">HandlePosn</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hSetPosn" class="link">Source</a></p><div class="doc"><p>If a call to <code><a href="IO.html#v:hGetPosn">hGetPosn</a></code> <code>hdl</code> returns a position <code>p</code>, then computation <code><a href="IO.html#v:hSetPosn">hSetPosn</a></code> <code>p</code> sets the position of <code>hdl</code> to the position it held at the time of the call to <code><a href="IO.html#v:hGetPosn">hGetPosn</a></code>. </p><p>This operation may fail with: </p><ul><li> <code>isPermissionError</code> if a system resource limit would be exceeded. </li></ul></div></div><div class="top"><p class="src"><a name="v:hSeek" class="def">hSeek</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:SeekMode">SeekMode</a> -> <a href="Prelude.html#t:Integer">Integer</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hSeek" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hSeek">hSeek</a></code> <code>hdl mode i</code> sets the position of handle <code>hdl</code> depending on <code>mode</code>. The offset <code>i</code> is given in terms of 8-bit bytes. </p><p>If <code>hdl</code> is block- or line-buffered, then seeking to a position which is not in the current buffer will first cause any items in the output buffer to be written to the device, and then cause the input buffer to be discarded. Some handles may not be seekable (see <code><a href="IO.html#v:hIsSeekable">hIsSeekable</a></code>), or only support a subset of the possible positioning operations (for instance, it may only be possible to seek to the end of a tape, or to a positive offset from the beginning or current position). It is not possible to set a negative I/O position, or for a physical file, an I/O position beyond the current end-of-file. </p><p>This operation may fail with: </p><ul><li> <code>isIllegalOperationError</code> if the Handle is not seekable, or does not support the requested seek mode. </li><li> <code>isPermissionError</code> if a system resource limit would be exceeded. </li></ul></div></div><div class="top"><p class="src"><a name="v:hWaitForInput" class="def">hWaitForInput</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:Int">Int</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/GHC-IO-Handle-Text.html#hWaitForInput" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hWaitForInput">hWaitForInput</a></code> <code>hdl t</code> waits until input is available on handle <code>hdl</code>. It returns <code><a href="Prelude.html#v:True">True</a></code> as soon as input is available on <code>hdl</code>, or <code><a href="Prelude.html#v:False">False</a></code> if no input is available within <code>t</code> milliseconds. Note that <code><a href="IO.html#v:hWaitForInput">hWaitForInput</a></code> waits until one or more full <em>characters</em> are available, which means that it needs to do decoding, and hence may fail with a decoding error. </p><p>If <code>t</code> is less than zero, then <code>hWaitForInput</code> waits indefinitely. </p><p>This operation may fail with: </p><ul><li> <code><a href="IO.html#v:isEOFError">isEOFError</a></code> if the end of file has been reached. </li><li> a decoding error, if the input begins with an invalid byte sequence in this Handle's encoding. </li></ul><p>NOTE for GHC users: unless you use the <code>-threaded</code> flag, <code>hWaitForInput t</code> where <code>t >= 0</code> will block all other Haskell threads for the duration of the call. It behaves like a <code>safe</code> foreign call in this respect. </p></div></div><div class="top"><p class="src"><a name="v:hReady" class="def">hReady</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO.html#hReady" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hReady">hReady</a></code> <code>hdl</code> indicates whether at least one item is available for input from handle <code>hdl</code>. </p><p>This operation may fail with: </p><ul><li> <code><a href="../base-4.5.1.0/System-IO-Error.html#v:isEOFError">isEOFError</a></code> if the end of file has been reached. </li></ul></div></div><div class="top"><p class="src"><a name="v:hGetChar" class="def">hGetChar</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Char">Char</a><a href="../base-4.5.1.0/src/GHC-IO-Handle-Text.html#hGetChar" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hGetChar">hGetChar</a></code> <code>hdl</code> reads a character from the file or channel managed by <code>hdl</code>, blocking until a character is available. </p><p>This operation may fail with: </p><ul><li> <code><a href="IO.html#v:isEOFError">isEOFError</a></code> if the end of file has been reached. </li></ul></div></div><div class="top"><p class="src"><a name="v:hGetLine" class="def">hGetLine</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:String">String</a><a href="../base-4.5.1.0/src/GHC-IO-Handle-Text.html#hGetLine" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hGetLine">hGetLine</a></code> <code>hdl</code> reads a line from the file or channel managed by <code>hdl</code>. </p><p>This operation may fail with: </p><ul><li> <code><a href="IO.html#v:isEOFError">isEOFError</a></code> if the end of file is encountered when reading the <em>first</em> character of the line. </li></ul><p>If <code><a href="IO.html#v:hGetLine">hGetLine</a></code> encounters end-of-file at any other point while reading in a line, it is treated as a line terminator and the (partial) line is returned. </p></div></div><div class="top"><p class="src"><a name="v:hLookAhead" class="def">hLookAhead</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Char">Char</a><a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hLookAhead" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hLookAhead">hLookAhead</a></code> returns the next character from the handle without removing it from the input buffer, blocking until a character is available. </p><p>This operation may fail with: </p><ul><li> <code>isEOFError</code> if the end of file has been reached. </li></ul></div></div><div class="top"><p class="src"><a name="v:hGetContents" class="def">hGetContents</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:String">String</a><a href="../base-4.5.1.0/src/GHC-IO-Handle-Text.html#hGetContents" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hGetContents">hGetContents</a></code> <code>hdl</code> returns the list of characters corresponding to the unread portion of the channel or file managed by <code>hdl</code>, which is put into an intermediate state, <em>semi-closed</em>. In this state, <code>hdl</code> is effectively closed, but items are read from <code>hdl</code> on demand and accumulated in a special list returned by <code><a href="IO.html#v:hGetContents">hGetContents</a></code> <code>hdl</code>. </p><p>Any operation that fails because a handle is closed, also fails if a handle is semi-closed. The only exception is <code>hClose</code>. A semi-closed handle becomes closed: </p><ul><li> if <code>hClose</code> is applied to it; </li><li> if an I/O error occurs when reading an item from the handle; </li><li> or once the entire contents of the handle has been read. </li></ul><p>Once a semi-closed handle becomes closed, the contents of the associated list becomes fixed. The contents of this final list is only partially specified: it will contain at least all the items of the stream that were evaluated prior to the handle becoming closed. </p><p>Any I/O errors encountered while a handle is semi-closed are simply discarded. </p><p>This operation may fail with: </p><ul><li> <code><a href="IO.html#v:isEOFError">isEOFError</a></code> if the end of file has been reached. </li></ul></div></div><div class="top"><p class="src"><a name="v:hPutChar" class="def">hPutChar</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:Char">Char</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/GHC-IO-Handle-Text.html#hPutChar" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hPutChar">hPutChar</a></code> <code>hdl ch</code> writes the character <code>ch</code> to the file or channel managed by <code>hdl</code>. Characters may be buffered if buffering is enabled for <code>hdl</code>. </p><p>This operation may fail with: </p><ul><li> <code><a href="IO.html#v:isFullError">isFullError</a></code> if the device is full; or </li><li> <code><a href="IO.html#v:isPermissionError">isPermissionError</a></code> if another system resource limit would be exceeded. </li></ul></div></div><div class="top"><p class="src"><a name="v:hPutStr" class="def">hPutStr</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/GHC-IO-Handle-Text.html#hPutStr" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hPutStr">hPutStr</a></code> <code>hdl s</code> writes the string <code>s</code> to the file or channel managed by <code>hdl</code>. </p><p>This operation may fail with: </p><ul><li> <code><a href="IO.html#v:isFullError">isFullError</a></code> if the device is full; or </li><li> <code><a href="IO.html#v:isPermissionError">isPermissionError</a></code> if another system resource limit would be exceeded. </li></ul></div></div><div class="top"><p class="src"><a name="v:hPutStrLn" class="def">hPutStrLn</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/GHC-IO-Handle-Text.html#hPutStrLn" class="link">Source</a></p><div class="doc"><p>The same as <code><a href="IO.html#v:hPutStr">hPutStr</a></code>, but adds a newline character. </p></div></div><div class="top"><p class="src"><a name="v:hPrint" class="def">hPrint</a> :: <a href="Prelude.html#t:Show">Show</a> a => <a href="IO.html#t:Handle">Handle</a> -> a -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/System-IO.html#hPrint" class="link">Source</a></p><div class="doc"><p>Computation <code><a href="IO.html#v:hPrint">hPrint</a></code> <code>hdl t</code> writes the string representation of <code>t</code> given by the <code><a href="Prelude.html#v:shows">shows</a></code> function to the file or channel managed by <code>hdl</code> and appends a newline. </p><p>This operation may fail with: </p><ul><li> <code><a href="../base-4.5.1.0/System-IO-Error.html#v:isFullError">isFullError</a></code> if the device is full; or </li><li> <code><a href="../base-4.5.1.0/System-IO-Error.html#v:isPermissionError">isPermissionError</a></code> if another system resource limit would be exceeded. </li></ul></div></div><div class="top"><p class="src"><a name="v:hIsOpen" class="def">hIsOpen</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hIsOpen" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:hIsClosed" class="def">hIsClosed</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hIsClosed" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:hIsReadable" class="def">hIsReadable</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hIsReadable" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:hIsWritable" class="def">hIsWritable</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hIsWritable" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:hIsSeekable" class="def">hIsSeekable</a> :: <a href="IO.html#t:Handle">Handle</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/GHC-IO-Handle.html#hIsSeekable" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:isAlreadyExistsError" class="def">isAlreadyExistsError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isAlreadyExistsError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="IO.html#t:IO">IO</a></code> operation failed because one of its arguments already exists. </p></div></div><div class="top"><p class="src"><a name="v:isDoesNotExistError" class="def">isDoesNotExistError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isDoesNotExistError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="IO.html#t:IO">IO</a></code> operation failed because one of its arguments does not exist. </p></div></div><div class="top"><p class="src"><a name="v:isAlreadyInUseError" class="def">isAlreadyInUseError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isAlreadyInUseError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="IO.html#t:IO">IO</a></code> 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). </p></div></div><div class="top"><p class="src"><a name="v:isFullError" class="def">isFullError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isFullError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="IO.html#t:IO">IO</a></code> operation failed because the device is full. </p></div></div><div class="top"><p class="src"><a name="v:isEOFError" class="def">isEOFError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isEOFError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="IO.html#t:IO">IO</a></code> operation failed because the end of file has been reached. </p></div></div><div class="top"><p class="src"><a name="v:isIllegalOperation" class="def">isIllegalOperation</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isIllegalOperation" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="IO.html#t:IO">IO</a></code> operation failed because the operation was not possible. Any computation which returns an <code><a href="IO.html#t:IO">IO</a></code> result may fail with <code><a href="IO.html#v:isIllegalOperation">isIllegalOperation</a></code>. In some cases, an implementation will not be able to distinguish between the possible error causes. In this case it should fail with <code><a href="IO.html#v:isIllegalOperation">isIllegalOperation</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:isPermissionError" class="def">isPermissionError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isPermissionError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="IO.html#t:IO">IO</a></code> operation failed because the user does not have sufficient operating system privilege to perform that operation. </p></div></div><div class="top"><p class="src"><a name="v:isUserError" class="def">isUserError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isUserError" class="link">Source</a></p><div class="doc"><p>A programmer-defined error value constructed using <code><a href="IO.html#v:userError">userError</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:ioeGetErrorString" class="def">ioeGetErrorString</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:String">String</a><a href="../base-4.5.1.0/src/System-IO-Error.html#ioeGetErrorString" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:ioeGetHandle" class="def">ioeGetHandle</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="IO.html#t:Handle">Handle</a><a href="../base-4.5.1.0/src/System-IO-Error.html#ioeGetHandle" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:ioeGetFileName" class="def">ioeGetFileName</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="IO.html#t:FilePath">FilePath</a><a href="../base-4.5.1.0/src/System-IO-Error.html#ioeGetFileName" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:try" class="def">try</a> :: <a href="IO.html#t:IO">IO</a> a -> <a href="IO.html#t:IO">IO</a> (<a href="Prelude.html#t:Either">Either</a> <a href="IO.html#t:IOError">IOError</a> a)</p><div class="doc"><p>The construct <code><a href="IO.html#v:try">try</a></code> <code>comp</code> exposes IO errors which occur within a computation, and which are not fully handled. </p><p>Non-I/O exceptions are not caught by this variant; to catch all exceptions, use <code><a href="../base-4.5.1.0/Control-Exception.html#v:try">try</a></code> from <a href="../base-4.5.1.0/Control-Exception.html">Control.Exception</a>. </p></div></div><div class="top"><p class="src"><a name="v:bracket" class="def">bracket</a> :: <a href="IO.html#t:IO">IO</a> a -> (a -> <a href="IO.html#t:IO">IO</a> b) -> (a -> <a href="IO.html#t:IO">IO</a> c) -> <a href="IO.html#t:IO">IO</a> c</p><div class="doc"><p>The <code><a href="IO.html#v:bracket">bracket</a></code> 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. </p><p>This version handles only IO errors, as defined by Haskell 98. The version of <code>bracket</code> in <a href="../base-4.5.1.0/Control-Exception.html">Control.Exception</a> handles all exceptions, and should be used instead. </p></div></div><div class="top"><p class="src"><a name="v:bracket_" class="def">bracket_</a> :: <a href="IO.html#t:IO">IO</a> a -> (a -> <a href="IO.html#t:IO">IO</a> b) -> <a href="IO.html#t:IO">IO</a> c -> <a href="IO.html#t:IO">IO</a> c</p><div class="doc"><p>A variant of <code><a href="IO.html#v:bracket">bracket</a></code> where the middle computation doesn't want <code>x</code>. </p><p>This version handles only IO errors, as defined by Haskell 98. The version of <code>bracket_</code> in <a href="../base-4.5.1.0/Control-Exception.html">Control.Exception</a> handles all exceptions, and should be used instead. </p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:IO" class="def">IO</a> a </p><div class="subs instances"><p id="control.i:IO" class="caption collapser" onclick="toggleSection('i:IO')">Instances</p><div id="section.i:IO" class="show"><table><tr><td class="src"><a href="Prelude.html#t:Monad">Monad</a> <a href="IO.html#t:IO">IO</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Functor">Functor</a> <a href="IO.html#t:IO">IO</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="../base-4.5.1.0/Data-Typeable-Internal.html#t:Typeable1">Typeable1</a> <a href="IO.html#t:IO">IO</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:FilePath" class="def">FilePath</a> = <a href="Prelude.html#t:String">String</a><a href="../base-4.5.1.0/src/GHC-IO.html#FilePath" class="link">Source</a></p><div class="doc"><p>File and directory names are values of type <code><a href="Prelude.html#t:String">String</a></code>, 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. </p></div></div><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:IOError" class="def">IOError</a> = <a href="../base-4.5.1.0/Control-Exception-Base.html#t:IOException">IOException</a><a href="../base-4.5.1.0/src/GHC-IO-Exception.html#IOError" class="link">Source</a></p><div class="doc"><p>The Haskell 98 type for exceptions in the <code><a href="IO.html#t:IO">IO</a></code> monad. Any I/O operation may raise an <code><a href="IO.html#t:IOError">IOError</a></code> instead of returning a result. For a more general type of exception, including also those that arise in pure code, see <a href="Control-Exception-Exception.html">Control.Exception.Exception</a>. </p><p>In Haskell 98, this is an opaque type. </p></div></div><div class="top"><p class="src"><a name="v:ioError" class="def">ioError</a> :: <a href="IO.html#t:IOError">IOError</a> -> <a href="IO.html#t:IO">IO</a> a<a href="../base-4.5.1.0/src/GHC-IO-Exception.html#ioError" class="link">Source</a></p><div class="doc"><p>Raise an <code><a href="IO.html#t:IOError">IOError</a></code> in the <code><a href="IO.html#t:IO">IO</a></code> monad. </p></div></div><div class="top"><p class="src"><a name="v:userError" class="def">userError</a> :: <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IOError">IOError</a><a href="../base-4.5.1.0/src/GHC-IO-Exception.html#userError" class="link">Source</a></p><div class="doc"><p>Construct an <code><a href="IO.html#t:IOError">IOError</a></code> value with a string describing the error. The <code><a href="Prelude.html#v:fail">fail</a></code> method of the <code><a href="IO.html#t:IO">IO</a></code> instance of the <code><a href="Prelude.html#t:Monad">Monad</a></code> class raises a <code><a href="IO.html#v:userError">userError</a></code>, thus: </p><pre> instance Monad IO where ... fail s = ioError (userError s) </pre></div></div><div class="top"><p class="src"><a name="v:catch" class="def">catch</a> :: <a href="IO.html#t:IO">IO</a> a -> (<a href="IO.html#t:IOError">IOError</a> -> <a href="IO.html#t:IO">IO</a> a) -> <a href="IO.html#t:IO">IO</a> a</p><div class="doc"><p>The <code><a href="IO.html#v:catch">catch</a></code> function establishes a handler that receives any <code><a href="IO.html#t:IOError">IOError</a></code> raised in the action protected by <code><a href="IO.html#v:catch">catch</a></code>. An <code><a href="IO.html#t:IOError">IOError</a></code> is caught by the most recent handler established by one of the exception handling functions. These handlers are not selective: all <code><a href="IO.html#t:IOError">IOError</a></code>s are caught. Exception propagation must be explicitly provided in a handler by re-raising any unwanted exceptions. For example, in </p><pre> f = catch g (\e -> if IO.isEOFError e then return [] else ioError e) </pre><p>the function <code>f</code> returns <code>[]</code> when an end-of-file exception (cf. <code><a href="../base-4.5.1.0/System-IO-Error.html#v:isEOFError">isEOFError</a></code>) occurs in <code>g</code>; otherwise, the exception is propagated to the next outer handler. </p><p>When an exception propagates outside the main program, the Haskell system prints the associated <code><a href="IO.html#t:IOError">IOError</a></code> value and exits the program. </p><p>Non-I/O exceptions are not caught by this variant; to catch all exceptions, use <code><a href="../base-4.5.1.0/Control-Exception.html#v:catch">catch</a></code> from <a href="../base-4.5.1.0/Control-Exception.html">Control.Exception</a>. </p></div></div><div class="top"><p class="src"><a name="v:interact" class="def">interact</a> :: (<a href="Prelude.html#t:String">String</a> -> <a href="Prelude.html#t:String">String</a>) -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/System-IO.html#interact" class="link">Source</a></p><div class="doc"><p>The <code><a href="IO.html#v:interact">interact</a></code> function takes a function of type <code>String->String</code> 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. </p></div></div><div class="top"><p class="src"><a name="v:putChar" class="def">putChar</a> :: <a href="Prelude.html#t:Char">Char</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/System-IO.html#putChar" class="link">Source</a></p><div class="doc"><p>Write a character to the standard output device (same as <code><a href="IO.html#v:hPutChar">hPutChar</a></code> <code><a href="IO.html#v:stdout">stdout</a></code>). </p></div></div><div class="top"><p class="src"><a name="v:putStr" class="def">putStr</a> :: <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/System-IO.html#putStr" class="link">Source</a></p><div class="doc"><p>Write a string to the standard output device (same as <code><a href="IO.html#v:hPutStr">hPutStr</a></code> <code><a href="IO.html#v:stdout">stdout</a></code>). </p></div></div><div class="top"><p class="src"><a name="v:putStrLn" class="def">putStrLn</a> :: <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/System-IO.html#putStrLn" class="link">Source</a></p><div class="doc"><p>The same as <code><a href="IO.html#v:putStr">putStr</a></code>, but adds a newline character. </p></div></div><div class="top"><p class="src"><a name="v:print" class="def">print</a> :: <a href="Prelude.html#t:Show">Show</a> a => a -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/System-IO.html#print" class="link">Source</a></p><div class="doc"><p>The <code><a href="IO.html#v:print">print</a></code> function outputs a value of any printable type to the standard output device. Printable types are those that are instances of class <code><a href="Prelude.html#t:Show">Show</a></code>; <code><a href="IO.html#v:print">print</a></code> converts values to strings for output using the <code><a href="Prelude.html#v:show">show</a></code> operation and adds a newline. </p><p>For example, a program to print the first 20 integers and their powers of 2 could be written as: </p><pre> main = print ([(n, 2^n) | n <- [0..19]]) </pre></div></div><div class="top"><p class="src"><a name="v:getChar" class="def">getChar</a> :: <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:Char">Char</a><a href="../base-4.5.1.0/src/System-IO.html#getChar" class="link">Source</a></p><div class="doc"><p>Read a character from the standard input device (same as <code><a href="IO.html#v:hGetChar">hGetChar</a></code> <code><a href="IO.html#v:stdin">stdin</a></code>). </p></div></div><div class="top"><p class="src"><a name="v:getLine" class="def">getLine</a> :: <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:String">String</a><a href="../base-4.5.1.0/src/System-IO.html#getLine" class="link">Source</a></p><div class="doc"><p>Read a line from the standard input device (same as <code><a href="IO.html#v:hGetLine">hGetLine</a></code> <code><a href="IO.html#v:stdin">stdin</a></code>). </p></div></div><div class="top"><p class="src"><a name="v:getContents" class="def">getContents</a> :: <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:String">String</a><a href="../base-4.5.1.0/src/System-IO.html#getContents" class="link">Source</a></p><div class="doc"><p>The <code><a href="IO.html#v:getContents">getContents</a></code> operation returns all user input as a single string, which is read lazily as it is needed (same as <code><a href="IO.html#v:hGetContents">hGetContents</a></code> <code><a href="IO.html#v:stdin">stdin</a></code>). </p></div></div><div class="top"><p class="src"><a name="v:readFile" class="def">readFile</a> :: <a href="IO.html#t:FilePath">FilePath</a> -> <a href="IO.html#t:IO">IO</a> <a href="Prelude.html#t:String">String</a><a href="../base-4.5.1.0/src/System-IO.html#readFile" class="link">Source</a></p><div class="doc"><p>The <code><a href="IO.html#v:readFile">readFile</a></code> function reads a file and returns the contents of the file as a string. The file is read lazily, on demand, as with <code><a href="IO.html#v:getContents">getContents</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:writeFile" class="def">writeFile</a> :: <a href="IO.html#t:FilePath">FilePath</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/System-IO.html#writeFile" class="link">Source</a></p><div class="doc"><p>The computation <code><a href="IO.html#v:writeFile">writeFile</a></code> <code>file str</code> function writes the string <code>str</code>, to the file <code>file</code>. </p></div></div><div class="top"><p class="src"><a name="v:appendFile" class="def">appendFile</a> :: <a href="IO.html#t:FilePath">FilePath</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/System-IO.html#appendFile" class="link">Source</a></p><div class="doc"><p>The computation <code><a href="IO.html#v:appendFile">appendFile</a></code> <code>file str</code> function appends the string <code>str</code>, to the file <code>file</code>. </p><p>Note that <code><a href="IO.html#v:writeFile">writeFile</a></code> and <code><a href="IO.html#v:appendFile">appendFile</a></code> write a literal string to a file. To write a value of any printable type, as with <code><a href="IO.html#v:print">print</a></code>, use the <code><a href="Prelude.html#v:show">show</a></code> function to convert the value to a string first. </p><pre> main = appendFile "squares" (show [(x,x*x) | x <- [0,0.1..2]]) </pre></div></div><div class="top"><p class="src"><a name="v:readIO" class="def">readIO</a> :: <a href="Prelude.html#t:Read">Read</a> a => <a href="Prelude.html#t:String">String</a> -> <a href="IO.html#t:IO">IO</a> a<a href="../base-4.5.1.0/src/System-IO.html#readIO" class="link">Source</a></p><div class="doc"><p>The <code><a href="IO.html#v:readIO">readIO</a></code> function is similar to <code><a href="Prelude.html#v:read">read</a></code> except that it signals parse failure to the <code><a href="IO.html#t:IO">IO</a></code> monad instead of terminating the program. </p></div></div><div class="top"><p class="src"><a name="v:readLn" class="def">readLn</a> :: <a href="Prelude.html#t:Read">Read</a> a => <a href="IO.html#t:IO">IO</a> a<a href="../base-4.5.1.0/src/System-IO.html#readLn" class="link">Source</a></p><div class="doc"><p>The <code><a href="IO.html#v:readLn">readLn</a></code> function combines <code><a href="IO.html#v:getLine">getLine</a></code> and <code><a href="IO.html#v:readIO">readIO</a></code>. </p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.11.0</p></div></body></html>