<!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>GHC.IO.Device</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_GHC-IO-Device.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>non-portable</td></tr><tr><th>Stability</th><td>internal</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">GHC.IO.Device</p></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Type classes for I/O providers. </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">class</span> <a href="#t:RawIO">RawIO</a> a <span class="keyword">where</span><ul class="subs"><li><a href="#v:read">read</a> :: a -> <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></li><li><a href="#v:readNonBlocking">readNonBlocking</a> :: a -> <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Maybe.html#t:Maybe">Maybe</a> <a href="Data-Int.html#t:Int">Int</a>)</li><li><a href="#v:write">write</a> :: a -> <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="Data-Int.html#t:Int">Int</a> -> <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><a href="#v:writeNonBlocking">writeNonBlocking</a> :: a -> <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></li></ul></li><li class="src short"><span class="keyword">class</span> <a href="#t:IODevice">IODevice</a> a <span class="keyword">where</span><ul class="subs"><li><a href="#v:ready">ready</a> :: a -> <a href="Data-Bool.html#t:Bool">Bool</a> -> <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:close">close</a> :: a -> <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><a href="#v:isTerminal">isTerminal</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:isSeekable">isSeekable</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:seek">seek</a> :: a -> <a href="GHC-IO-Device.html#t:SeekMode">SeekMode</a> -> <a href="Prelude.html#t:Integer">Integer</a> -> <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><a href="#v:tell">tell</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="Prelude.html#t:Integer">Integer</a></li><li><a href="#v:getSize">getSize</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="Prelude.html#t:Integer">Integer</a></li><li><a href="#v:setSize">setSize</a> :: a -> <a href="Prelude.html#t:Integer">Integer</a> -> <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><a href="#v:setEcho">setEcho</a> :: a -> <a href="Data-Bool.html#t:Bool">Bool</a> -> <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><a href="#v:getEcho">getEcho</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:setRaw">setRaw</a> :: a -> <a href="Data-Bool.html#t:Bool">Bool</a> -> <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><a href="#v:devType">devType</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-IO-Device.html#t:IODeviceType">IODeviceType</a></li><li><a href="#v:dup">dup</a> :: a -> <a href="System-IO.html#t:IO">IO</a> a</li><li><a href="#v:dup2">dup2</a> :: a -> a -> <a href="System-IO.html#t:IO">IO</a> a</li></ul></li><li class="src short"><span class="keyword">data</span> <a href="#t:IODeviceType">IODeviceType</a> <ul class="subs"><li>= <a href="#v:Directory">Directory</a> </li><li>| <a href="#v:Stream">Stream</a> </li><li>| <a href="#v:RegularFile">RegularFile</a> </li><li>| <a href="#v:RawDevice">RawDevice</a> </li></ul></li><li class="src short"><span class="keyword">data</span> <a href="#t:SeekMode">SeekMode</a> <ul class="subs"><li>= <a href="#v:AbsoluteSeek">AbsoluteSeek</a> </li><li>| <a href="#v:RelativeSeek">RelativeSeek</a> </li><li>| <a href="#v:SeekFromEnd">SeekFromEnd</a> </li></ul></li></ul></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><span class="keyword">class</span> <a name="t:RawIO" class="def">RawIO</a> a <span class="keyword">where</span></p><div class="doc"><p>A low-level I/O provider where the data is bytes in memory. </p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:read" class="def">read</a> :: a -> <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></p><div class="doc"><p>Read up to the specified number of bytes, returning the number of bytes actually read. This function should only block if there is no data available. If there is not enough data available, then the function should just return the available data. A return value of zero indicates that the end of the data stream (e.g. end of file) has been reached. </p></div><p class="src"><a name="v:readNonBlocking" class="def">readNonBlocking</a> :: a -> <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Maybe.html#t:Maybe">Maybe</a> <a href="Data-Int.html#t:Int">Int</a>)</p><div class="doc"><p>Read up to the specified number of bytes, returning the number of bytes actually read, or <code><a href="Data-Maybe.html#v:Nothing">Nothing</a></code> if the end of the stream has been reached. </p></div><p class="src"><a name="v:write" class="def">write</a> :: a -> <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="Data-Int.html#t:Int">Int</a> -> <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 the specified number of bytes. </p></div><p class="src"><a name="v:writeNonBlocking" class="def">writeNonBlocking</a> :: a -> <a href="Foreign-Ptr.html#t:Ptr">Ptr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></p><div class="doc"><p>Write up to the specified number of bytes without blocking. Returns the actual number of bytes written. </p></div></div><div class="subs instances"><p id="control.i:RawIO" class="caption collapser" onclick="toggleSection('i:RawIO')">Instances</p><div id="section.i:RawIO" class="show"><table><tr><td class="src"><a href="GHC-IO-Device.html#t:RawIO">RawIO</a> FD</td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">class</span> <a name="t:IODevice" class="def">IODevice</a> a <span class="keyword">where</span></p><div class="doc"><p>I/O operations required for implementing a <code>Handle</code>. </p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:ready" class="def">ready</a> :: a -> <a href="Data-Bool.html#t:Bool">Bool</a> -> <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p><code>ready dev write msecs</code> returns <code><a href="Data-Bool.html#v:True">True</a></code> if the device has data to read (if <code>write</code> is <code><a href="Data-Bool.html#v:False">False</a></code>) or space to write new data (if <code>write</code> is <code><a href="Data-Bool.html#v:True">True</a></code>). <code>msecs</code> specifies how long to wait, in milliseconds. </p></div><p class="src"><a name="v:close" class="def">close</a> :: a -> <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>closes the device. Further operations on the device should produce exceptions. </p></div><p class="src"><a name="v:isTerminal" class="def">isTerminal</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>returns <code><a href="Data-Bool.html#v:True">True</a></code> if the device is a terminal or console. </p></div><p class="src"><a name="v:isSeekable" class="def">isSeekable</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>returns <code><a href="Data-Bool.html#v:True">True</a></code> if the device supports <code><a href="GHC-IO-Device.html#v:seek">seek</a></code> operations. </p></div><p class="src"><a name="v:seek" class="def">seek</a> :: a -> <a href="GHC-IO-Device.html#t:SeekMode">SeekMode</a> -> <a href="Prelude.html#t:Integer">Integer</a> -> <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>seek to the specified position in the data. </p></div><p class="src"><a name="v:tell" class="def">tell</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="Prelude.html#t:Integer">Integer</a></p><div class="doc"><p>return the current position in the data. </p></div><p class="src"><a name="v:getSize" class="def">getSize</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="Prelude.html#t:Integer">Integer</a></p><div class="doc"><p>return the size of the data. </p></div><p class="src"><a name="v:setSize" class="def">setSize</a> :: a -> <a href="Prelude.html#t:Integer">Integer</a> -> <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>change the size of the data. </p></div><p class="src"><a name="v:setEcho" class="def">setEcho</a> :: a -> <a href="Data-Bool.html#t:Bool">Bool</a> -> <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>for terminal devices, changes whether characters are echoed on the device. </p></div><p class="src"><a name="v:getEcho" class="def">getEcho</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>returns the current echoing status. </p></div><p class="src"><a name="v:setRaw" class="def">setRaw</a> :: a -> <a href="Data-Bool.html#t:Bool">Bool</a> -> <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>some devices (e.g. terminals) support a <a href="raw.html">raw</a> mode where characters entered are immediately made available to the program. If available, this operations enables raw mode. </p></div><p class="src"><a name="v:devType" class="def">devType</a> :: a -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-IO-Device.html#t:IODeviceType">IODeviceType</a></p><div class="doc"><p>returns the <code><a href="GHC-IO-Device.html#t:IODeviceType">IODeviceType</a></code> corresponding to this device. </p></div><p class="src"><a name="v:dup" class="def">dup</a> :: a -> <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>duplicates the device, if possible. The new device is expected to share a file pointer with the original device (like Unix <code>dup</code>). </p></div><p class="src"><a name="v:dup2" class="def">dup2</a> :: a -> a -> <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p><code>dup2 source target</code> replaces the target device with the source device. The target device is closed first, if necessary, and then it is made into a duplicate of the first device (like Unix <code>dup2</code>). </p></div></div><div class="subs instances"><p id="control.i:IODevice" class="caption collapser" onclick="toggleSection('i:IODevice')">Instances</p><div id="section.i:IODevice" class="show"><table><tr><td class="src"><a href="GHC-IO-Device.html#t:IODevice">IODevice</a> FD</td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:IODeviceType" class="def">IODeviceType</a> </p><div class="doc"><p>Type of a device that can be used to back a <code><a href="GHC-IO-Handle.html#t:Handle">Handle</a></code> (see also <code><a href="GHC-IO-Handle.html#v:mkFileHandle">mkFileHandle</a></code>). The standard libraries provide creation of <code><a href="GHC-IO-Handle.html#t:Handle">Handle</a></code>s via Posix file operations with file descriptors (see <code><a href="GHC-IO-Handle-FD.html#v:mkHandleFromFD">mkHandleFromFD</a></code>) with FD being the underlying <code><a href="GHC-IO-Device.html#t:IODevice">IODevice</a></code> instance. </p><p>Users may provide custom instances of <code><a href="GHC-IO-Device.html#t:IODevice">IODevice</a></code> which are expected to conform the following rules: </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:Directory" class="def">Directory</a></td><td class="doc"><p>The standard libraries do not have direct support for this device type, but a user implementation is expected to provide a list of file names in the directory, in any order, separated by <code>'\0'</code> characters, excluding the <code><a href="-.html">.</a></code> and <code><a href="--.html">..</a></code> names. See also <code><a href="System-Directory.html#v:getDirectoryContents">getDirectoryContents</a></code>. Seek operations are not supported on directories (other than to the zero position). </p></td></tr><tr><td class="src"><a name="v:Stream" class="def">Stream</a></td><td class="doc"><p>A duplex communications channel (results in creation of a duplex <code><a href="GHC-IO-Handle.html#t:Handle">Handle</a></code>). The standard libraries use this device type when creating <code><a href="GHC-IO-Handle.html#t:Handle">Handle</a></code>s for open sockets. </p></td></tr><tr><td class="src"><a name="v:RegularFile" class="def">RegularFile</a></td><td class="doc"><p>A file that may be read or written, and also may be seekable. </p></td></tr><tr><td class="src"><a name="v:RawDevice" class="def">RawDevice</a></td><td class="doc"><p>A <a href="raw.html">raw</a> (disk) device which supports block binary read and write operations and may be seekable only to positions of certain granularity (block- aligned). </p></td></tr></table></div><div class="subs instances"><p id="control.i:IODeviceType" class="caption collapser" onclick="toggleSection('i:IODeviceType')">Instances</p><div id="section.i:IODeviceType" class="show"><table><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="GHC-IO-Device.html#t:IODeviceType">IODeviceType</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:SeekMode" class="def">SeekMode</a> </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="GHC-IO-Device.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="GHC-IO-Device.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="GHC-IO-Device.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Text-Read.html#t:Read">Read</a> <a href="GHC-IO-Device.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="GHC-IO-Device.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ix.html#t:Ix">Ix</a> <a href="GHC-IO-Device.html#t:SeekMode">SeekMode</a></td><td class="doc empty"> </td></tr></table></div></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>