Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-release > by-pkgid > 6e204a966e8c42d976f99a1700ce5f20 > files > 2326

ghc-7.4.2-4.mga5.i586.rpm

<!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>System.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_System-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">base-4.5.1.0: Basic libraries</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>portable</td></tr><tr><th>Stability</th><td>stable</td></tr><tr><th>Maintainer</th><td>libraries@haskell.org</td></tr><tr><th>Safe Haskell</th><td>Trustworthy</td></tr></table><p class="caption">System.IO</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">The IO monad
</a></li><li><a href="#g:2">Files and handles
</a><ul><li><a href="#g:3">Standard handles
</a></li></ul></li><li><a href="#g:4">Opening and closing files
</a><ul><li><a href="#g:5">Opening files
</a></li><li><a href="#g:6">Closing files
</a></li><li><a href="#g:7">Special cases
</a></li><li><a href="#g:8">File locking
</a></li></ul></li><li><a href="#g:9">Operations on handles
</a><ul><li><a href="#g:10">Determining and changing the size of a file
</a></li><li><a href="#g:11">Detecting the end of input
</a></li><li><a href="#g:12">Buffering operations
</a></li><li><a href="#g:13">Repositioning handles
</a></li><li><a href="#g:14">Handle properties
</a></li><li><a href="#g:15">Terminal operations (not portable: GHC/Hugs only)
</a></li><li><a href="#g:16">Showing handle state (not portable: GHC only)
</a></li></ul></li><li><a href="#g:17">Text input and output
</a><ul><li><a href="#g:18">Text input
</a></li><li><a href="#g:19">Text output
</a></li><li><a href="#g:20">Special cases for standard input and output
</a></li></ul></li><li><a href="#g:21">Binary input and output
</a></li><li><a href="#g:22">Temporary files
</a></li><li><a href="#g:23">Unicode encoding/decoding
</a><ul><li><a href="#g:24">Unicode encodings
</a></li></ul></li><li><a href="#g:25">Newline conversion
</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>The standard IO library.
</p></div></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:IO">IO</a> a</li><li class="src short"><a href="#v:fixIO">fixIO</a> ::  (a -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><span class="keyword">type</span> <a href="#t:FilePath">FilePath</a> = <a href="Data-String.html#t:String">String</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:Handle">Handle</a> </li><li class="src short"><a href="#v:stdin">stdin</a> :: <a href="System-IO.html#t:Handle">Handle</a></li><li class="src short"><a href="#v:stdout">stdout</a> :: <a href="System-IO.html#t:Handle">Handle</a></li><li class="src short"><a href="#v:stderr">stderr</a> :: <a href="System-IO.html#t:Handle">Handle</a></li><li class="src short"><a href="#v:withFile">withFile</a> ::  <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO.html#t:IOMode">IOMode</a> -&gt; (<a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> r) -&gt; <a href="System-IO.html#t:IO">IO</a> r</li><li class="src short"><a href="#v:openFile">openFile</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO.html#t:IOMode">IOMode</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="System-IO.html#t:Handle">Handle</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"><a href="#v:hClose">hClose</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:readFile">readFile</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:writeFile">writeFile</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:appendFile">appendFile</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hFileSize">hFileSize</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Prelude.html#t:Integer">Integer</a></li><li class="src short"><a href="#v:hSetFileSize">hSetFileSize</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Prelude.html#t:Integer">Integer</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hIsEOF">hIsEOF</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isEOF">isEOF</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></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="Data-Maybe.html#t:Maybe">Maybe</a> <a href="Data-Int.html#t:Int">Int</a>)  </li></ul></li><li class="src short"><a href="#v:hSetBuffering">hSetBuffering</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:BufferMode">BufferMode</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hGetBuffering">hGetBuffering</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="System-IO.html#t:BufferMode">BufferMode</a></li><li class="src short"><a href="#v:hFlush">hFlush</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hGetPosn">hGetPosn</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="System-IO.html#t:HandlePosn">HandlePosn</a></li><li class="src short"><a href="#v:hSetPosn">hSetPosn</a> :: <a href="System-IO.html#t:HandlePosn">HandlePosn</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:HandlePosn">HandlePosn</a> </li><li class="src short"><a href="#v:hSeek">hSeek</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:SeekMode">SeekMode</a> -&gt; <a href="Prelude.html#t:Integer">Integer</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></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:hTell">hTell</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Prelude.html#t:Integer">Integer</a></li><li class="src short"><a href="#v:hIsOpen">hIsOpen</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hIsClosed">hIsClosed</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hIsReadable">hIsReadable</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hIsWritable">hIsWritable</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hIsSeekable">hIsSeekable</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hIsTerminalDevice">hIsTerminalDevice</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hSetEcho">hSetEcho</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-Bool.html#t:Bool">Bool</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hGetEcho">hGetEcho</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hShow">hShow</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:hWaitForInput">hWaitForInput</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hReady">hReady</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:hGetChar">hGetChar</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Char.html#t:Char">Char</a></li><li class="src short"><a href="#v:hGetLine">hGetLine</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:hLookAhead">hLookAhead</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Char.html#t:Char">Char</a></li><li class="src short"><a href="#v:hGetContents">hGetContents</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:hPutChar">hPutChar</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-Char.html#t:Char">Char</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hPutStr">hPutStr</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hPutStrLn">hPutStrLn</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hPrint">hPrint</a> :: <a href="Text-Show.html#t:Show">Show</a> a =&gt; <a href="System-IO.html#t:Handle">Handle</a> -&gt; a -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:interact">interact</a> :: (<a href="Data-String.html#t:String">String</a> -&gt; <a href="Data-String.html#t:String">String</a>) -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:putChar">putChar</a> :: <a href="Data-Char.html#t:Char">Char</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:putStr">putStr</a> :: <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:putStrLn">putStrLn</a> :: <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:print">print</a> :: <a href="Text-Show.html#t:Show">Show</a> a =&gt; a -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:getChar">getChar</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Data-Char.html#t:Char">Char</a></li><li class="src short"><a href="#v:getLine">getLine</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:getContents">getContents</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:readIO">readIO</a> :: <a href="Text-Read.html#t:Read">Read</a> a =&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:readLn">readLn</a> :: <a href="Text-Read.html#t:Read">Read</a> a =&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:withBinaryFile">withBinaryFile</a> ::  <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO.html#t:IOMode">IOMode</a> -&gt; (<a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> r) -&gt; <a href="System-IO.html#t:IO">IO</a> r</li><li class="src short"><a href="#v:openBinaryFile">openBinaryFile</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO.html#t:IOMode">IOMode</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="System-IO.html#t:Handle">Handle</a></li><li class="src short"><a href="#v:hSetBinaryMode">hSetBinaryMode</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-Bool.html#t:Bool">Bool</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hPutBuf">hPutBuf</a> ::  <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> a -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hGetBuf">hGetBuf</a> ::  <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> a -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:hGetBufSome">hGetBufSome</a> ::  <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> a -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:hPutBufNonBlocking">hPutBufNonBlocking</a> ::  <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> a -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:hGetBufNonBlocking">hGetBufNonBlocking</a> ::  <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> a -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:openTempFile">openTempFile</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="System-IO.html#t:FilePath">FilePath</a>, <a href="System-IO.html#t:Handle">Handle</a>)</li><li class="src short"><a href="#v:openBinaryTempFile">openBinaryTempFile</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="System-IO.html#t:FilePath">FilePath</a>, <a href="System-IO.html#t:Handle">Handle</a>)</li><li class="src short"><a href="#v:openTempFileWithDefaultPermissions">openTempFileWithDefaultPermissions</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="System-IO.html#t:FilePath">FilePath</a>, <a href="System-IO.html#t:Handle">Handle</a>)</li><li class="src short"><a href="#v:openBinaryTempFileWithDefaultPermissions">openBinaryTempFileWithDefaultPermissions</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="System-IO.html#t:FilePath">FilePath</a>, <a href="System-IO.html#t:Handle">Handle</a>)</li><li class="src short"><a href="#v:hSetEncoding">hSetEncoding</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:TextEncoding">TextEncoding</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hGetEncoding">hGetEncoding</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Maybe.html#t:Maybe">Maybe</a> <a href="System-IO.html#t:TextEncoding">TextEncoding</a>)</li><li class="src short"><span class="keyword">data</span>  <a href="#t:TextEncoding">TextEncoding</a> </li><li class="src short"><a href="#v:latin1">latin1</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:utf8">utf8</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:utf8_bom">utf8_bom</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:utf16">utf16</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:utf16le">utf16le</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:utf16be">utf16be</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:utf32">utf32</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:utf32le">utf32le</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:utf32be">utf32be</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:localeEncoding">localeEncoding</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:char8">char8</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:mkTextEncoding">mkTextEncoding</a> :: <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="System-IO.html#t:TextEncoding">TextEncoding</a></li><li class="src short"><a href="#v:hSetNewlineMode">hSetNewlineMode</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:NewlineMode">NewlineMode</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:Newline">Newline</a> <ul class="subs"><li>= <a href="#v:LF">LF</a>  </li><li>| <a href="#v:CRLF">CRLF</a>  </li></ul></li><li class="src short"><a href="#v:nativeNewline">nativeNewline</a> :: <a href="System-IO.html#t:Newline">Newline</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:NewlineMode">NewlineMode</a>  = <a href="#v:NewlineMode">NewlineMode</a> {<ul class="subs"><li><a href="#v:inputNL">inputNL</a> :: <a href="System-IO.html#t:Newline">Newline</a></li><li><a href="#v:outputNL">outputNL</a> :: <a href="System-IO.html#t:Newline">Newline</a></li></ul>}</li><li class="src short"><a href="#v:noNewlineTranslation">noNewlineTranslation</a> :: <a href="System-IO.html#t:NewlineMode">NewlineMode</a></li><li class="src short"><a href="#v:universalNewlineMode">universalNewlineMode</a> :: <a href="System-IO.html#t:NewlineMode">NewlineMode</a></li><li class="src short"><a href="#v:nativeNewlineMode">nativeNewlineMode</a> :: <a href="System-IO.html#t:NewlineMode">NewlineMode</a></li></ul></div><div id="interface"><h1 id="g:1">The IO monad
</h1><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:IO" class="def">IO</a> a <a href="../ghc-prim-0.2.0.0/src/GHC-Types.html#IO" class="link">Source</a></p><div class="doc"><p>A value of type <code><code><a href="System-IO.html#t:IO">IO</a></code> a</code> is a computation which, when performed,
does some I/O before returning a value of type <code>a</code>.
</p><p>There is really only one way to &quot;perform&quot; an I/O action: bind it to
<code>Main.main</code> in your program.  When your program is run, the I/O will
be performed.  It isn't possible to perform I/O from an arbitrary
function, unless that function is itself in the <code><a href="System-IO.html#t:IO">IO</a></code> monad and called
at some point, directly or indirectly, from <code>Main.main</code>.
</p><p><code><a href="System-IO.html#t:IO">IO</a></code> is a monad, so <code><a href="System-IO.html#t:IO">IO</a></code> actions can be combined using either the do-notation
or the <code>&gt;&gt;</code> and <code>&gt;&gt;=</code> operations from the <code>Monad</code> class.
</p></div><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="Control-Monad.html#t:Monad">Monad</a> <a href="System-IO.html#t:IO">IO</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Monad.html#t:Functor">Functor</a> <a href="System-IO.html#t:IO">IO</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable1">Typeable1</a> <a href="System-IO.html#t:IO">IO</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Monad-Fix.html#t:MonadFix">MonadFix</a> <a href="System-IO.html#t:IO">IO</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Applicative.html#t:Applicative">Applicative</a> <a href="System-IO.html#t:IO">IO</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Printf.html#t:HPrintfType">HPrintfType</a> (<a href="System-IO.html#t:IO">IO</a> a)</td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Printf.html#t:PrintfType">PrintfType</a> (<a href="System-IO.html#t:IO">IO</a> a)</td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:fixIO" class="def">fixIO</a> ::  (a -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> a</p></div><h1 id="g:2">Files and handles
</h1><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:FilePath" class="def">FilePath</a> = <a href="Data-String.html#t:String">String</a></p><div class="doc"><p>File and directory names are values of type <code><a href="Data-String.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">data</span>  <a name="t:Handle" class="def">Handle</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="Text-Show.html#t:Show">Show</a></code> and <code><a href="Data-Eq.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="Data-Eq.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="Data-Eq.html#t:Eq">Eq</a> <a href="System-IO.html#t:Handle">Handle</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="System-IO.html#t:Handle">Handle</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="System-IO.html#t:Handle">Handle</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="doc"><p>GHC note: a <code><a href="System-IO.html#t:Handle">Handle</a></code> will be automatically closed when the garbage
 collector detects that it has become unreferenced by the program.
 However, relying on this behaviour is not generally recommended:
 the garbage collector is unpredictable.  If possible, use
 an explicit <code><a href="System-IO.html#v:hClose">hClose</a></code> to close <code><a href="System-IO.html#t:Handle">Handle</a></code>s when they are no longer
 required.  GHC does not currently attempt to free up file
 descriptors when they have run out, it is your responsibility to
 ensure that this doesn't happen.
</p></div><h2 id="g:3">Standard handles
</h2><div class="doc"><p>Three handles are allocated during program initialisation,
 and are initially open.
</p></div><div class="top"><p class="src"><a name="v:stdin" class="def">stdin</a> :: <a href="System-IO.html#t:Handle">Handle</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="System-IO.html#t:Handle">Handle</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="System-IO.html#t:Handle">Handle</a></p><div class="doc"><p>A handle managing output to the Haskell program's standard error channel.
</p></div></div><h1 id="g:4">Opening and closing files
</h1><h2 id="g:5">Opening files
</h2><div class="top"><p class="src"><a name="v:withFile" class="def">withFile</a> ::  <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO.html#t:IOMode">IOMode</a> -&gt; (<a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> r) -&gt; <a href="System-IO.html#t:IO">IO</a> r</p><div class="doc"><p><code><code><a href="System-IO.html#v:withFile">withFile</a></code> name mode act</code> opens a file using <code><a href="System-IO.html#v:openFile">openFile</a></code> and passes
 the resulting handle to the computation <code>act</code>.  The handle will be
 closed on exit from <code><a href="System-IO.html#v:withFile">withFile</a></code>, whether by normal termination or by
 raising an exception.  If closing the handle raises an exception, then
 this exception will be raised by <code><a href="System-IO.html#v:withFile">withFile</a></code> rather than any exception
 raised by <code>act</code>.
</p></div></div><div class="top"><p class="src"><a name="v:openFile" class="def">openFile</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO.html#t:IOMode">IOMode</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="System-IO.html#t:Handle">Handle</a></p><div class="doc"><p>Computation <code><a href="System-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="System-IO.html#v:ReadMode">ReadMode</a></code>, output if <code>mode</code> is <code><a href="System-IO.html#v:WriteMode">WriteMode</a></code> or <code><a href="System-IO.html#v:AppendMode">AppendMode</a></code>,
 and both input and output if mode is <code><a href="System-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="System-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="System-IO.html#v:openFile">openFile</a></code> with <code>mode</code>
 <code><a href="System-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="System-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="System-IO.html#v:openBinaryFile">openBinaryFile</a></code>.
</p></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:IOMode" class="def">IOMode</a>  </p><div class="doc"><p>See <code><a href="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">&nbsp;</td></tr><tr><td class="src"><a name="v:WriteMode" class="def">WriteMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a name="v:AppendMode" class="def">AppendMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a name="v:ReadWriteMode" class="def">ReadWriteMode</a></td><td class="doc empty">&nbsp;</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="System-IO.html#t:IOMode">IOMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="System-IO.html#t:IOMode">IOMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="System-IO.html#t:IOMode">IOMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Read.html#t:Read">Read</a> <a href="System-IO.html#t:IOMode">IOMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="System-IO.html#t:IOMode">IOMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="System-IO.html#t:IOMode">IOMode</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><h2 id="g:6">Closing files
</h2><div class="top"><p class="src"><a name="v:hClose" class="def">hClose</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Computation <code><a href="System-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="System-IO.html#v:hFlush">hFlush</a></code>.
 Performing <code><a href="System-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="System-IO.html#v:hClose">hClose</a></code> fails for any reason, any further operations (apart from
 <code><a href="System-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><h2 id="g:7">Special cases
</h2><div class="doc"><p>These functions are also exported by the <a href="Prelude.html">Prelude</a>.
</p></div><div class="top"><p class="src"><a name="v:readFile" class="def">readFile</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></p><div class="doc"><p>The <code><a href="System-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="System-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="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>The computation <code><a href="System-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="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>The computation <code><a href="System-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="System-IO.html#v:writeFile">writeFile</a></code> and <code><a href="System-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="System-IO.html#v:print">print</a></code>,
 use the <code><a href="Text-Show.html#v:show">show</a></code> function to convert the value to a string first.
</p><pre> main = appendFile &quot;squares&quot; (show [(x,x*x) | x &lt;- [0,0.1..2]])
</pre></div></div><h2 id="g:8">File locking
</h2><div class="doc"><p>Implementations should enforce as far as possible, at least locally to the
 Haskell process, multiple-reader single-writer locking on files.
 That is, <em>there may either be many handles on the same file which manage input, or just one handle on the file which manages output</em>.  If any
 open or semi-closed handle is managing a file for output, no new
 handle can be allocated for that file.  If any open or semi-closed
 handle is managing a file for input, new handles can only be allocated
 if they do not manage output.  Whether two files are the same is
 implementation-dependent, but they should normally be the same if they
 have the same absolute path name and neither has been renamed, for
 example.
</p><p><em>Warning</em>: the <code><a href="System-IO.html#v:readFile">readFile</a></code> operation holds a semi-closed handle on
 the file until the entire contents of the file have been consumed.
 It follows that an attempt to write to a file (using <code><a href="System-IO.html#v:writeFile">writeFile</a></code>, for
 example) that was earlier opened by <code><a href="System-IO.html#v:readFile">readFile</a></code> will usually result in
 failure with <code><a href="System-IO-Error.html#v:isAlreadyInUseError">isAlreadyInUseError</a></code>.
</p></div><h1 id="g:9">Operations on handles
</h1><h2 id="g:10">Determining and changing the size of a file
</h2><div class="top"><p class="src"><a name="v:hFileSize" class="def">hFileSize</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Prelude.html#t:Integer">Integer</a></p><div class="doc"><p>For a handle <code>hdl</code> which attached to a physical file,
 <code><a href="System-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:hSetFileSize" class="def">hSetFileSize</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Prelude.html#t:Integer">Integer</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p><code><a href="System-IO.html#v:hSetFileSize">hSetFileSize</a></code> <code>hdl</code> <code>size</code> truncates the physical file with handle <code>hdl</code> to <code>size</code> bytes.
</p></div></div><h2 id="g:11">Detecting the end of input
</h2><div class="top"><p class="src"><a name="v:hIsEOF" class="def">hIsEOF</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>For a readable handle <code>hdl</code>, <code><a href="System-IO.html#v:hIsEOF">hIsEOF</a></code> <code>hdl</code> returns
 <code><a href="Data-Bool.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="Data-Bool.html#v:False">False</a></code>.
</p><p>NOTE: <code><a href="System-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="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>The computation <code><a href="System-IO.html#v:isEOF">isEOF</a></code> is identical to <code><a href="System-IO.html#v:hIsEOF">hIsEOF</a></code>,
 except that it works only on <code><a href="System-IO.html#v:stdin">stdin</a></code>.
</p></div></div><h2 id="g:12">Buffering operations
</h2><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:BufferMode" class="def">BufferMode</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="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="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="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="Data-Maybe.html#t:Maybe">Maybe</a> <a href="Data-Int.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="Data-Maybe.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="Data-Eq.html#t:Eq">Eq</a> <a href="System-IO.html#t:BufferMode">BufferMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="System-IO.html#t:BufferMode">BufferMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Read.html#t:Read">Read</a> <a href="System-IO.html#t:BufferMode">BufferMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="System-IO.html#t:BufferMode">BufferMode</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:hSetBuffering" class="def">hSetBuffering</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:BufferMode">BufferMode</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Computation <code><a href="System-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="System-IO.html#v:BlockBuffering">BlockBuffering</a></code> or
 <code><a href="System-IO.html#v:LineBuffering">LineBuffering</a></code> to <code><a href="System-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="System-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="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="System-IO.html#t:BufferMode">BufferMode</a></p><div class="doc"><p>Computation <code><a href="System-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="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>The action <code><a href="System-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><h2 id="g:13">Repositioning handles
</h2><div class="top"><p class="src"><a name="v:hGetPosn" class="def">hGetPosn</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="System-IO.html#t:HandlePosn">HandlePosn</a></p><div class="doc"><p>Computation <code><a href="System-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="System-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="System-IO.html#t:HandlePosn">HandlePosn</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>If a call to <code><a href="System-IO.html#v:hGetPosn">hGetPosn</a></code> <code>hdl</code> returns a position <code>p</code>,
 then computation <code><a href="System-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="System-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"><span class="keyword">data</span>  <a name="t:HandlePosn" class="def">HandlePosn</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="Data-Eq.html#t:Eq">Eq</a> <a href="System-IO.html#t:HandlePosn">HandlePosn</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="System-IO.html#t:HandlePosn">HandlePosn</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:hSeek" class="def">hSeek</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:SeekMode">SeekMode</a> -&gt; <a href="Prelude.html#t:Integer">Integer</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Computation <code><a href="System-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="System-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"><span class="keyword">data</span>  <a name="t:SeekMode" class="def">SeekMode</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="System-IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="System-IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="System-IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Read.html#t:Read">Read</a> <a href="System-IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="System-IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="System-IO.html#t:SeekMode">SeekMode</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:hTell" class="def">hTell</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Prelude.html#t:Integer">Integer</a></p><div class="doc"><p>Computation <code><a href="System-IO.html#v:hTell">hTell</a></code> <code>hdl</code> returns the current position of the
 handle <code>hdl</code>, as the number of bytes from the beginning of
 the file.  The value returned may be subsequently passed to
 <code><a href="System-IO.html#v:hSeek">hSeek</a></code> to reposition the handle to the current position.
</p><p>This operation may fail with:
</p><ul><li> <code>isIllegalOperationError</code> if the Handle is not seekable.
</li></ul></div></div><h2 id="g:14">Handle properties
</h2><div class="top"><p class="src"><a name="v:hIsOpen" class="def">hIsOpen</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p></div><div class="top"><p class="src"><a name="v:hIsClosed" class="def">hIsClosed</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p></div><div class="top"><p class="src"><a name="v:hIsReadable" class="def">hIsReadable</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p></div><div class="top"><p class="src"><a name="v:hIsWritable" class="def">hIsWritable</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p></div><div class="top"><p class="src"><a name="v:hIsSeekable" class="def">hIsSeekable</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p></div><h2 id="g:15">Terminal operations (not portable: GHC/Hugs only)
</h2><div class="top"><p class="src"><a name="v:hIsTerminalDevice" class="def">hIsTerminalDevice</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Is the handle connected to a terminal?
</p></div></div><div class="top"><p class="src"><a name="v:hSetEcho" class="def">hSetEcho</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-Bool.html#t:Bool">Bool</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Set the echoing status of a handle connected to a terminal.
</p></div></div><div class="top"><p class="src"><a name="v:hGetEcho" class="def">hGetEcho</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Get the echoing status of a handle connected to a terminal.
</p></div></div><h2 id="g:16">Showing handle state (not portable: GHC only)
</h2><div class="top"><p class="src"><a name="v:hShow" class="def">hShow</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></p><div class="doc"><p><code><a href="System-IO.html#v:hShow">hShow</a></code> is in the <code><a href="System-IO.html#t:IO">IO</a></code> monad, and gives more comprehensive output
 than the (pure) instance of <code><a href="Text-Show.html#t:Show">Show</a></code> for <code><a href="System-IO.html#t:Handle">Handle</a></code>.
</p></div></div><h1 id="g:17">Text input and output
</h1><h2 id="g:18">Text input
</h2><div class="top"><p class="src"><a name="v:hWaitForInput" class="def">hWaitForInput</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Computation <code><a href="System-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="Data-Bool.html#v:True">True</a></code> as soon as input is available on <code>hdl</code>,
 or <code><a href="Data-Bool.html#v:False">False</a></code> if no input is available within <code>t</code> milliseconds.  Note that
 <code><a href="System-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="System-IO-Error.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 &gt;= 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="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Computation <code><a href="System-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="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="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Char.html#t:Char">Char</a></p><div class="doc"><p>Computation <code><a href="System-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="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:hGetLine" class="def">hGetLine</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></p><div class="doc"><p>Computation <code><a href="System-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="System-IO-Error.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="System-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="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Char.html#t:Char">Char</a></p><div class="doc"><p>Computation <code><a href="System-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="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></p><div class="doc"><p>Computation <code><a href="System-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="System-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="System-IO-Error.html#v:isEOFError">isEOFError</a></code> if the end of file has been reached.
</li></ul></div></div><h2 id="g:19">Text output
</h2><div class="top"><p class="src"><a name="v:hPutChar" class="def">hPutChar</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-Char.html#t:Char">Char</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Computation <code><a href="System-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="System-IO-Error.html#v:isFullError">isFullError</a></code> if the device is full; or
</li><li> <code><a href="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:hPutStr" class="def">hPutStr</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Computation <code><a href="System-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="System-IO-Error.html#v:isFullError">isFullError</a></code> if the device is full; or
</li><li> <code><a href="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:hPutStrLn" class="def">hPutStrLn</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>The same as <code><a href="System-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="Text-Show.html#t:Show">Show</a> a =&gt; <a href="System-IO.html#t:Handle">Handle</a> -&gt; a -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Computation <code><a href="System-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="Text-Show.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="System-IO-Error.html#v:isFullError">isFullError</a></code> if the device is full; or
</li><li> <code><a href="System-IO-Error.html#v:isPermissionError">isPermissionError</a></code> if another system resource limit would be exceeded.
</li></ul></div></div><h2 id="g:20">Special cases for standard input and output
</h2><div class="doc"><p>These functions are also exported by the <a href="Prelude.html">Prelude</a>.
</p></div><div class="top"><p class="src"><a name="v:interact" class="def">interact</a> :: (<a href="Data-String.html#t:String">String</a> -&gt; <a href="Data-String.html#t:String">String</a>) -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>The <code><a href="System-IO.html#v:interact">interact</a></code> function takes a function of type <code>String-&gt;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="Data-Char.html#t:Char">Char</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Write a character to the standard output device
 (same as <code><a href="System-IO.html#v:hPutChar">hPutChar</a></code> <code><a href="System-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="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Write a string to the standard output device
 (same as <code><a href="System-IO.html#v:hPutStr">hPutStr</a></code> <code><a href="System-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="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>The same as <code><a href="System-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="Text-Show.html#t:Show">Show</a> a =&gt; a -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>The <code><a href="System-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="Text-Show.html#t:Show">Show</a></code>; <code><a href="System-IO.html#v:print">print</a></code>
 converts values to strings for output using the <code><a href="Text-Show.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 &lt;- [0..19]])
</pre></div></div><div class="top"><p class="src"><a name="v:getChar" class="def">getChar</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Data-Char.html#t:Char">Char</a></p><div class="doc"><p>Read a character from the standard input device
 (same as <code><a href="System-IO.html#v:hGetChar">hGetChar</a></code> <code><a href="System-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="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></p><div class="doc"><p>Read a line from the standard input device
 (same as <code><a href="System-IO.html#v:hGetLine">hGetLine</a></code> <code><a href="System-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="System-IO.html#t:IO">IO</a> <a href="Data-String.html#t:String">String</a></p><div class="doc"><p>The <code><a href="System-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="System-IO.html#v:hGetContents">hGetContents</a></code> <code><a href="System-IO.html#v:stdin">stdin</a></code>).
</p></div></div><div class="top"><p class="src"><a name="v:readIO" class="def">readIO</a> :: <a href="Text-Read.html#t:Read">Read</a> a =&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>The <code><a href="System-IO.html#v:readIO">readIO</a></code> function is similar to <code><a href="Text-Read.html#v:read">read</a></code> except that it signals
 parse failure to the <code><a href="System-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="Text-Read.html#t:Read">Read</a> a =&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>The <code><a href="System-IO.html#v:readLn">readLn</a></code> function combines <code><a href="System-IO.html#v:getLine">getLine</a></code> and <code><a href="System-IO.html#v:readIO">readIO</a></code>.
</p></div></div><h1 id="g:21">Binary input and output
</h1><div class="top"><p class="src"><a name="v:withBinaryFile" class="def">withBinaryFile</a> ::  <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO.html#t:IOMode">IOMode</a> -&gt; (<a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> r) -&gt; <a href="System-IO.html#t:IO">IO</a> r</p><div class="doc"><p><code><code><a href="System-IO.html#v:withBinaryFile">withBinaryFile</a></code> name mode act</code> opens a file using <code><a href="System-IO.html#v:openBinaryFile">openBinaryFile</a></code>
 and passes the resulting handle to the computation <code>act</code>.  The handle
 will be closed on exit from <code><a href="System-IO.html#v:withBinaryFile">withBinaryFile</a></code>, whether by normal
 termination or by raising an exception.
</p></div></div><div class="top"><p class="src"><a name="v:openBinaryFile" class="def">openBinaryFile</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO.html#t:IOMode">IOMode</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="System-IO.html#t:Handle">Handle</a></p><div class="doc"><p>Like <code><a href="System-IO.html#v:openFile">openFile</a></code>, but open the file in binary mode.
 On Windows, reading a file in text mode (which is the default)
 will translate CRLF to LF, and writing will translate LF to CRLF.
 This is usually what you want with text files.  With binary files
 this is undesirable; also, as usual under Microsoft operating systems,
 text mode treats control-Z as EOF.  Binary mode turns off all special
 treatment of end-of-line and end-of-file characters.
 (See also <code><a href="System-IO.html#v:hSetBinaryMode">hSetBinaryMode</a></code>.)
</p></div></div><div class="top"><p class="src"><a name="v:hSetBinaryMode" class="def">hSetBinaryMode</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Data-Bool.html#t:Bool">Bool</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Select binary mode (<code><a href="Data-Bool.html#v:True">True</a></code>) or text mode (<code><a href="Data-Bool.html#v:False">False</a></code>) on a open handle.
 (See also <code>openBinaryFile</code>.)
</p><p>This has the same effect as calling <code><a href="System-IO.html#v:hSetEncoding">hSetEncoding</a></code> with <code><a href="System-IO.html#v:char8">char8</a></code>, together
 with <code><a href="System-IO.html#v:hSetNewlineMode">hSetNewlineMode</a></code> with <code><a href="System-IO.html#v:noNewlineTranslation">noNewlineTranslation</a></code>.
</p></div></div><div class="top"><p class="src"><a name="v:hPutBuf" class="def">hPutBuf</a> ::  <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> a -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p><code><a href="System-IO.html#v:hPutBuf">hPutBuf</a></code> <code>hdl buf count</code> writes <code>count</code> 8-bit bytes from the
 buffer <code>buf</code> to the handle <code>hdl</code>.  It returns ().
</p><p><code><a href="System-IO.html#v:hPutBuf">hPutBuf</a></code> ignores any text encoding that applies to the <code><a href="System-IO.html#t:Handle">Handle</a></code>,
 writing the bytes directly to the underlying file or device.
</p><p><code><a href="System-IO.html#v:hPutBuf">hPutBuf</a></code> ignores the prevailing <code>TextEncoding</code> and
 <code><a href="System-IO.html#t:NewlineMode">NewlineMode</a></code> on the <code><a href="System-IO.html#t:Handle">Handle</a></code>, and writes bytes directly.
</p><p>This operation may fail with:
</p><ul><li> <code>ResourceVanished</code> if the handle is a pipe or socket, and the
    reading end is closed.  (If this is a POSIX system, and the program
    has not asked to ignore SIGPIPE, then a SIGPIPE may be delivered
    instead, whose default action is to terminate the program).
</li></ul></div></div><div class="top"><p class="src"><a name="v:hGetBuf" class="def">hGetBuf</a> ::  <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> a -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></p><div class="doc"><p><code><a href="System-IO.html#v:hGetBuf">hGetBuf</a></code> <code>hdl buf count</code> reads data from the handle <code>hdl</code>
 into the buffer <code>buf</code> until either EOF is reached or
 <code>count</code> 8-bit bytes have been read.
 It returns the number of bytes actually read.  This may be zero if
 EOF was reached before any data was read (or if <code>count</code> is zero).
</p><p><code><a href="System-IO.html#v:hGetBuf">hGetBuf</a></code> never raises an EOF exception, instead it returns a value
 smaller than <code>count</code>.
</p><p>If the handle is a pipe or socket, and the writing end
 is closed, <code><a href="System-IO.html#v:hGetBuf">hGetBuf</a></code> will behave as if EOF was reached.
</p><p><code><a href="System-IO.html#v:hGetBuf">hGetBuf</a></code> ignores the prevailing <code>TextEncoding</code> and <code><a href="System-IO.html#t:NewlineMode">NewlineMode</a></code>
 on the <code><a href="System-IO.html#t:Handle">Handle</a></code>, and reads bytes directly.
</p></div></div><div class="top"><p class="src"><a name="v:hGetBufSome" class="def">hGetBufSome</a> ::  <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> a -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></p><div class="doc"><p><code><a href="System-IO.html#v:hGetBufSome">hGetBufSome</a></code> <code>hdl buf count</code> reads data from the handle <code>hdl</code>
 into the buffer <code>buf</code>.  If there is any data available to read,
 then <code><a href="System-IO.html#v:hGetBufSome">hGetBufSome</a></code> returns it immediately; it only blocks if there
 is no data to be read.
</p><p>It returns the number of bytes actually read.  This may be zero if
 EOF was reached before any data was read (or if <code>count</code> is zero).
</p><p><code><a href="System-IO.html#v:hGetBufSome">hGetBufSome</a></code> never raises an EOF exception, instead it returns a value
 smaller than <code>count</code>.
</p><p>If the handle is a pipe or socket, and the writing end
 is closed, <code><a href="System-IO.html#v:hGetBufSome">hGetBufSome</a></code> will behave as if EOF was reached.
</p><p><code><a href="System-IO.html#v:hGetBufSome">hGetBufSome</a></code> ignores the prevailing <code>TextEncoding</code> and <code><a href="System-IO.html#t:NewlineMode">NewlineMode</a></code>
 on the <code><a href="System-IO.html#t:Handle">Handle</a></code>, and reads bytes directly.
</p></div></div><div class="top"><p class="src"><a name="v:hPutBufNonBlocking" class="def">hPutBufNonBlocking</a> ::  <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> a -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></p></div><div class="top"><p class="src"><a name="v:hGetBufNonBlocking" class="def">hGetBufNonBlocking</a> ::  <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> a -&gt; <a href="Data-Int.html#t:Int">Int</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></p><div class="doc"><p><code><a href="System-IO.html#v:hGetBufNonBlocking">hGetBufNonBlocking</a></code> <code>hdl buf count</code> reads data from the handle <code>hdl</code>
 into the buffer <code>buf</code> until either EOF is reached, or
 <code>count</code> 8-bit bytes have been read, or there is no more data available
 to read immediately.
</p><p><code><a href="System-IO.html#v:hGetBufNonBlocking">hGetBufNonBlocking</a></code> is identical to <code><a href="System-IO.html#v:hGetBuf">hGetBuf</a></code>, except that it will
 never block waiting for data to become available, instead it returns
 only whatever data is available.  To wait for data to arrive before
 calling <code><a href="System-IO.html#v:hGetBufNonBlocking">hGetBufNonBlocking</a></code>, use <code><a href="System-IO.html#v:hWaitForInput">hWaitForInput</a></code>.
</p><p>If the handle is a pipe or socket, and the writing end
 is closed, <code><a href="System-IO.html#v:hGetBufNonBlocking">hGetBufNonBlocking</a></code> will behave as if EOF was reached.
</p><p><code><a href="System-IO.html#v:hGetBufNonBlocking">hGetBufNonBlocking</a></code> ignores the prevailing <code>TextEncoding</code> and
 <code><a href="System-IO.html#t:NewlineMode">NewlineMode</a></code> on the <code><a href="System-IO.html#t:Handle">Handle</a></code>, and reads bytes directly.
</p><p>NOTE: on Windows, this function does not work correctly; it
 behaves identically to <code><a href="System-IO.html#v:hGetBuf">hGetBuf</a></code>.
</p></div></div><h1 id="g:22">Temporary files
</h1><div class="top"><p class="src"><a name="v:openTempFile" class="def">openTempFile</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="System-IO.html#t:FilePath">FilePath</a></td><td class="doc"><p>Directory in which to create the file
</p></td></tr><tr><td class="src">-&gt; <a href="Data-String.html#t:String">String</a></td><td class="doc"><p>File name template. If the template is &quot;foo.ext&quot; then
 the created file will be &quot;fooXXX.ext&quot; where XXX is some
 random number.
</p></td></tr><tr><td class="src">-&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="System-IO.html#t:FilePath">FilePath</a>, <a href="System-IO.html#t:Handle">Handle</a>)</td><td class="doc empty">&nbsp;</td></tr></table></div><div class="doc"><p>The function creates a temporary file in ReadWrite mode.
 The created file isn't deleted automatically, so you need to delete it manually.
</p><p>The file is creates with permissions such that only the current
 user can read/write it.
</p><p>With some exceptions (see below), the file will be created securely
 in the sense that an attacker should not be able to cause
 openTempFile to overwrite another file on the filesystem using your
 credentials, by putting symbolic links (on Unix) in the place where
 the temporary file is to be created.  On Unix the <code>O_CREAT</code> and
 <code>O_EXCL</code> flags are used to prevent this attack, but note that
 <code>O_EXCL</code> is sometimes not supported on NFS filesystems, so if you
 rely on this behaviour it is best to use local filesystems only.
</p></div></div><div class="top"><p class="src"><a name="v:openBinaryTempFile" class="def">openBinaryTempFile</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="System-IO.html#t:FilePath">FilePath</a>, <a href="System-IO.html#t:Handle">Handle</a>)</p><div class="doc"><p>Like <code><a href="System-IO.html#v:openTempFile">openTempFile</a></code>, but opens the file in binary mode. See <code><a href="System-IO.html#v:openBinaryFile">openBinaryFile</a></code> for more comments.
</p></div></div><div class="top"><p class="src"><a name="v:openTempFileWithDefaultPermissions" class="def">openTempFileWithDefaultPermissions</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="System-IO.html#t:FilePath">FilePath</a>, <a href="System-IO.html#t:Handle">Handle</a>)</p><div class="doc"><p>Like <code><a href="System-IO.html#v:openTempFile">openTempFile</a></code>, but uses the default file permissions
</p></div></div><div class="top"><p class="src"><a name="v:openBinaryTempFileWithDefaultPermissions" class="def">openBinaryTempFileWithDefaultPermissions</a> :: <a href="System-IO.html#t:FilePath">FilePath</a> -&gt; <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="System-IO.html#t:FilePath">FilePath</a>, <a href="System-IO.html#t:Handle">Handle</a>)</p><div class="doc"><p>Like <code><a href="System-IO.html#v:openBinaryTempFile">openBinaryTempFile</a></code>, but uses the default file permissions
</p></div></div><h1 id="g:23">Unicode encoding/decoding
</h1><div class="doc"><p>A text-mode <code><a href="System-IO.html#t:Handle">Handle</a></code> has an associated <code><a href="System-IO.html#t:TextEncoding">TextEncoding</a></code>, which
 is used to decode bytes into Unicode characters when reading,
 and encode Unicode characters into bytes when writing.
</p><p>The default <code><a href="System-IO.html#t:TextEncoding">TextEncoding</a></code> is the same as the default encoding
 on your system, which is also available as <code><a href="System-IO.html#v:localeEncoding">localeEncoding</a></code>.
 (GHC note: on Windows, we currently do not support double-byte
 encodings; if the console's code page is unsupported, then
 <code><a href="System-IO.html#v:localeEncoding">localeEncoding</a></code> will be <code><a href="System-IO.html#v:latin1">latin1</a></code>.)
</p><p>Encoding and decoding errors are always detected and reported,
 except during lazy I/O (<code><a href="System-IO.html#v:hGetContents">hGetContents</a></code>, <code><a href="System-IO.html#v:getContents">getContents</a></code>, and
 <code><a href="System-IO.html#v:readFile">readFile</a></code>), where a decoding error merely results in
 termination of the character stream, as with other I/O errors.
</p></div><div class="top"><p class="src"><a name="v:hSetEncoding" class="def">hSetEncoding</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:TextEncoding">TextEncoding</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>The action <code><a href="System-IO.html#v:hSetEncoding">hSetEncoding</a></code> <code>hdl</code> <code>encoding</code> changes the text encoding
 for the handle <code>hdl</code> to <code>encoding</code>.  The default encoding when a <code><a href="System-IO.html#t:Handle">Handle</a></code> is
 created is <code>localeEncoding</code>, namely the default encoding for the current
 locale.
</p><p>To create a <code><a href="System-IO.html#t:Handle">Handle</a></code> with no encoding at all, use <code>openBinaryFile</code>.  To
 stop further encoding or decoding on an existing <code><a href="System-IO.html#t:Handle">Handle</a></code>, use
 <code><a href="System-IO.html#v:hSetBinaryMode">hSetBinaryMode</a></code>.
</p><p><code><a href="System-IO.html#v:hSetEncoding">hSetEncoding</a></code> may need to flush buffered data in order to change
 the encoding.
</p></div></div><div class="top"><p class="src"><a name="v:hGetEncoding" class="def">hGetEncoding</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Maybe.html#t:Maybe">Maybe</a> <a href="System-IO.html#t:TextEncoding">TextEncoding</a>)</p><div class="doc"><p>Return the current <code><a href="System-IO.html#t:TextEncoding">TextEncoding</a></code> for the specified <code><a href="System-IO.html#t:Handle">Handle</a></code>, or
 <code><a href="Data-Maybe.html#v:Nothing">Nothing</a></code> if the <code><a href="System-IO.html#t:Handle">Handle</a></code> is in binary mode.
</p><p>Note that the <code><a href="System-IO.html#t:TextEncoding">TextEncoding</a></code> remembers nothing about the state of
 the encoder/decoder in use on this <code><a href="System-IO.html#t:Handle">Handle</a></code>.  For example, if the
 encoding in use is UTF-16, then using <code><a href="System-IO.html#v:hGetEncoding">hGetEncoding</a></code> and
 <code><a href="System-IO.html#v:hSetEncoding">hSetEncoding</a></code> to save and restore the encoding may result in an
 extra byte-order-mark being written to the file.
</p></div></div><h2 id="g:24">Unicode encodings
</h2><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:TextEncoding" class="def">TextEncoding</a>  </p><div class="doc"><p>A <code><a href="System-IO.html#t:TextEncoding">TextEncoding</a></code> is a specification of a conversion scheme
 between sequences of bytes and sequences of Unicode characters.
</p><p>For example, UTF-8 is an encoding of Unicode characters into a sequence
 of bytes.  The <code><a href="System-IO.html#t:TextEncoding">TextEncoding</a></code> for UTF-8 is <code>utf8</code>.
</p></div><div class="subs instances"><p id="control.i:TextEncoding" class="caption collapser" onclick="toggleSection('i:TextEncoding')">Instances</p><div id="section.i:TextEncoding" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="System-IO.html#t:TextEncoding">TextEncoding</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:latin1" class="def">latin1</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>The Latin1 (ISO8859-1) encoding.  This encoding maps bytes
 directly to the first 256 Unicode code points, and is thus not a
 complete Unicode encoding.  An attempt to write a character greater than
 '\255' to a <code>Handle</code> using the <code><a href="System-IO.html#v:latin1">latin1</a></code> encoding will result in an error.
</p></div></div><div class="top"><p class="src"><a name="v:utf8" class="def">utf8</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>The UTF-8 Unicode encoding
</p></div></div><div class="top"><p class="src"><a name="v:utf8_bom" class="def">utf8_bom</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>The UTF-8 Unicode encoding, with a byte-order-mark (BOM; the byte
 sequence 0xEF 0xBB 0xBF).  This encoding behaves like <code><a href="System-IO.html#v:utf8">utf8</a></code>,
 except that on input, the BOM sequence is ignored at the beginning
 of the stream, and on output, the BOM sequence is prepended.
</p><p>The byte-order-mark is strictly unnecessary in UTF-8, but is
 sometimes used to identify the encoding of a file.
</p></div></div><div class="top"><p class="src"><a name="v:utf16" class="def">utf16</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>The UTF-16 Unicode encoding (a byte-order-mark should be used to
 indicate endianness).
</p></div></div><div class="top"><p class="src"><a name="v:utf16le" class="def">utf16le</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>The UTF-16 Unicode encoding (litte-endian)
</p></div></div><div class="top"><p class="src"><a name="v:utf16be" class="def">utf16be</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>The UTF-16 Unicode encoding (big-endian)
</p></div></div><div class="top"><p class="src"><a name="v:utf32" class="def">utf32</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>The UTF-32 Unicode encoding (a byte-order-mark should be used to
 indicate endianness).
</p></div></div><div class="top"><p class="src"><a name="v:utf32le" class="def">utf32le</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>The UTF-32 Unicode encoding (litte-endian)
</p></div></div><div class="top"><p class="src"><a name="v:utf32be" class="def">utf32be</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>The UTF-32 Unicode encoding (big-endian)
</p></div></div><div class="top"><p class="src"><a name="v:localeEncoding" class="def">localeEncoding</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>The Unicode encoding of the current locale
</p><p>This is the initial locale encoding: if it has been subsequently changed by
 <code><a href="GHC-IO-Encoding.html#v:setLocaleEncoding">setLocaleEncoding</a></code> this value will not reflect that change.
</p></div></div><div class="top"><p class="src"><a name="v:char8" class="def">char8</a> :: <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>An encoding in which Unicode code points are translated to bytes
 by taking the code point modulo 256.  When decoding, bytes are
 translated directly into the equivalent code point.
</p><p>This encoding never fails in either direction.  However, encoding
 discards information, so encode followed by decode is not the
 identity.
</p></div></div><div class="top"><p class="src"><a name="v:mkTextEncoding" class="def">mkTextEncoding</a> :: <a href="Data-String.html#t:String">String</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="System-IO.html#t:TextEncoding">TextEncoding</a></p><div class="doc"><p>Look up the named Unicode encoding.  May fail with 
</p><ul><li> <code>isDoesNotExistError</code> if the encoding is unknown
</li></ul><p>The set of known encodings is system-dependent, but includes at least:
</p><ul><li><pre>UTF-8</pre></li><li> <code>UTF-16</code>, <code>UTF-16BE</code>, <code>UTF-16LE</code>
</li><li> <code>UTF-32</code>, <code>UTF-32BE</code>, <code>UTF-32LE</code>
</li></ul><p>On systems using GNU iconv (e.g. Linux), there is additional
 notation for specifying how illegal characters are handled:
</p><ul><li> a suffix of <code>//IGNORE</code>, e.g. <code>UTF-8//IGNORE</code>, will cause 
    all illegal sequences on input to be ignored, and on output
    will drop all code points that have no representation in the
    target encoding.
</li><li> a suffix of <code>//TRANSLIT</code> will choose a replacement character
    for illegal sequences or code points.
</li></ul><p>On Windows, you can access supported code pages with the prefix
 <code>CP</code>; for example, <code>&quot;CP1250&quot;</code>.
</p></div></div><h1 id="g:25">Newline conversion
</h1><div class="doc"><p>In Haskell, a newline is always represented by the character
 '\n'.  However, in files and external character streams, a
 newline may be represented by another character sequence, such
 as '\r\n'.
</p><p>A text-mode <code><a href="System-IO.html#t:Handle">Handle</a></code> has an associated <code><a href="System-IO.html#t:NewlineMode">NewlineMode</a></code> that
 specifies how to transate newline characters.  The
 <code><a href="System-IO.html#t:NewlineMode">NewlineMode</a></code> specifies the input and output translation
 separately, so that for instance you can translate '\r\n'
 to '\n' on input, but leave newlines as '\n' on output.
</p><p>The default <code><a href="System-IO.html#t:NewlineMode">NewlineMode</a></code> for a <code><a href="System-IO.html#t:Handle">Handle</a></code> is
 <code><a href="System-IO.html#v:nativeNewlineMode">nativeNewlineMode</a></code>, which does no translation on Unix systems,
 but translates '\r\n' to '\n' and back on Windows.
</p><p>Binary-mode <code><a href="System-IO.html#t:Handle">Handle</a></code>s do no newline translation at all.
</p></div><div class="top"><p class="src"><a name="v:hSetNewlineMode" class="def">hSetNewlineMode</a> :: <a href="System-IO.html#t:Handle">Handle</a> -&gt; <a href="System-IO.html#t:NewlineMode">NewlineMode</a> -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Set the <code><a href="System-IO.html#t:NewlineMode">NewlineMode</a></code> on the specified <code><a href="System-IO.html#t:Handle">Handle</a></code>.  All buffered
 data is flushed first.
</p></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:Newline" class="def">Newline</a>  </p><div class="doc"><p>The representation of a newline in the external file or stream.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:LF" class="def">LF</a></td><td class="doc"><p>'\n'
</p></td></tr><tr><td class="src"><a name="v:CRLF" class="def">CRLF</a></td><td class="doc"><p>'\r\n'
</p></td></tr></table></div><div class="subs instances"><p id="control.i:Newline" class="caption collapser" onclick="toggleSection('i:Newline')">Instances</p><div id="section.i:Newline" class="show"><table><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="System-IO.html#t:Newline">Newline</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="System-IO.html#t:Newline">Newline</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Read.html#t:Read">Read</a> <a href="System-IO.html#t:Newline">Newline</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="System-IO.html#t:Newline">Newline</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:nativeNewline" class="def">nativeNewline</a> :: <a href="System-IO.html#t:Newline">Newline</a></p><div class="doc"><p>The native newline representation for the current platform: <code><a href="System-IO.html#v:LF">LF</a></code>
 on Unix systems, <code><a href="System-IO.html#v:CRLF">CRLF</a></code> on Windows.
</p></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:NewlineMode" class="def">NewlineMode</a>  </p><div class="doc"><p>Specifies the translation, if any, of newline characters between
 internal Strings and the external file or stream.  Haskell Strings
 are assumed to represent newlines with the '\n' character; the
 newline mode specifies how to translate '\n' on output, and what to
 translate into '\n' on input.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:NewlineMode" class="def">NewlineMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><div class="subs fields"><p class="caption">Fields</p><dl><dt class="src"><a name="v:inputNL" class="def">inputNL</a> :: <a href="System-IO.html#t:Newline">Newline</a></dt><dd class="doc"><p>the representation of newlines on input
</p></dd><dt class="src"><a name="v:outputNL" class="def">outputNL</a> :: <a href="System-IO.html#t:Newline">Newline</a></dt><dd class="doc"><p>the representation of newlines on output
</p></dd></dl><div class="clear"></div></div></td></tr></table></div><div class="subs instances"><p id="control.i:NewlineMode" class="caption collapser" onclick="toggleSection('i:NewlineMode')">Instances</p><div id="section.i:NewlineMode" class="show"><table><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="System-IO.html#t:NewlineMode">NewlineMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="System-IO.html#t:NewlineMode">NewlineMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Read.html#t:Read">Read</a> <a href="System-IO.html#t:NewlineMode">NewlineMode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="System-IO.html#t:NewlineMode">NewlineMode</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:noNewlineTranslation" class="def">noNewlineTranslation</a> :: <a href="System-IO.html#t:NewlineMode">NewlineMode</a></p><div class="doc"><p>Do no newline translation at all.
</p><pre> noNewlineTranslation  = NewlineMode { inputNL  = LF, outputNL = LF }
</pre></div></div><div class="top"><p class="src"><a name="v:universalNewlineMode" class="def">universalNewlineMode</a> :: <a href="System-IO.html#t:NewlineMode">NewlineMode</a></p><div class="doc"><p>Map '\r\n' into '\n' on input, and '\n' to the native newline
 represetnation on output.  This mode can be used on any platform, and
 works with text files using any newline convention.  The downside is
 that <code>readFile &gt;&gt;= writeFile</code> might yield a different file.
</p><pre> universalNewlineMode  = NewlineMode { inputNL  = CRLF, 
                                       outputNL = nativeNewline }
</pre></div></div><div class="top"><p class="src"><a name="v:nativeNewlineMode" class="def">nativeNewlineMode</a> :: <a href="System-IO.html#t:NewlineMode">NewlineMode</a></p><div class="doc"><p>Use the native newline representation on both input and output
</p><pre> nativeNewlineMode  = NewlineMode { inputNL  = nativeNewline
                                    outputNL = nativeNewline }
</pre></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>