Files
dotfiles/cabal/share/doc/x86_64-osx-ghc-7.10.1/MissingH-1.3.0.1/html/System-IO-Utils.html
2015-04-05 17:47:08 +02:00

27 lines
19 KiB
HTML

<!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.Utils</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-Utils.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">MissingH-1.3.0.1: Large utility library</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Copyright</th><td>Copyright (C) 2004-2011 John Goerzen</td></tr><tr><th>License</th><td>BSD3</td></tr><tr><th>Maintainer</th><td>John Goerzen &lt;jgoerzen@complete.org&gt;</td></tr><tr><th>Stability</th><td>provisional</td></tr><tr><th>Portability</th><td>portable</td></tr><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell98</td></tr></table><p class="caption">System.IO.Utils</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Entire File Handle Utilities</a><ul><li><a href="#g:2">Opened Handle Data Copying</a></li><li><a href="#g:3">Disk File Data Copying</a></li></ul></li><li><a href="#g:4">Line Processing Utilities</a></li><li><a href="#g:5">Lazy Interaction</a><ul><li><a href="#g:6">Character-based</a></li><li><a href="#g:7">Line-based</a></li><li><a href="#g:8">Misc. Lazy</a></li></ul></li><li><a href="#g:9">Optimizations</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc empty">&nbsp;</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"><a href="#v:hCopy">hCopy</a> :: (<a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a, <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> b) =&gt; a -&gt; b -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hCopyProgress">hCopyProgress</a> :: (<a href="System-IO-HVIO.html#t:HVIO">HVIO</a> b, <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> c, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integral">Integral</a> a) =&gt; b -&gt; c -&gt; (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Maybe.html#t:Maybe">Maybe</a> a -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integer">Integer</a> -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a> -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()) -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a> -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Maybe.html#t:Maybe">Maybe</a> a -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integer">Integer</a></li><li class="src short"><a href="#v:hLineCopy">hLineCopy</a> :: (<a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a, <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> b) =&gt; a -&gt; b -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:lineCopy">lineCopy</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:copyFileLinesToFile">copyFileLinesToFile</a> :: <a href="System-IO-HVFS.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO-HVFS.html#t:FilePath">FilePath</a> -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hPutStrLns">hPutStrLns</a> :: <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a =&gt; a -&gt; [<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>] -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hGetLines">hGetLines</a> :: <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a =&gt; a -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> [<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>]</li><li class="src short"><a href="#v:hInteract">hInteract</a> :: (<a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a, <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> b) =&gt; a -&gt; b -&gt; (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>) -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:hLineInteract">hLineInteract</a> :: (<a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a, <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> b) =&gt; a -&gt; b -&gt; ([<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>] -&gt; [<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>]) -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:lineInteract">lineInteract</a> :: ([<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>] -&gt; [<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>]) -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:lazyMapM">lazyMapM</a> :: (a -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> b) -&gt; [a] -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> [b]</li><li class="src short"><a href="#v:optimizeForBatch">optimizeForBatch</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:optimizeForInteraction">optimizeForInteraction</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li></ul></div><div id="interface"><h1 id="g:1">Entire File Handle Utilities</h1><h2 id="g:2">Opened Handle Data Copying</h2><div class="top"><p class="src"><a name="v:hCopy" class="def">hCopy</a> :: (<a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a, <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> b) =&gt; a -&gt; b -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Copies from one handle to another in raw mode (using
hGetContents).</p></div></div><div class="top"><p class="src"><a name="v:hCopyProgress" class="def">hCopyProgress</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: (<a href="System-IO-HVIO.html#t:HVIO">HVIO</a> b, <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> c, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integral">Integral</a> a)</td><td class="doc empty">&nbsp;</td></tr><tr><td class="src">=&gt; b</td><td class="doc"><p>Input handle</p></td></tr><tr><td class="src">-&gt; c</td><td class="doc"><p>Output handle</p></td></tr><tr><td class="src">-&gt; (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Maybe.html#t:Maybe">Maybe</a> a -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integer">Integer</a> -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a> -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ())</td><td class="doc"><p>Progress function -- the bool is always False unless this is the final call</p></td></tr><tr><td class="src">-&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src">-&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Maybe.html#t:Maybe">Maybe</a> a</td><td class="doc empty">&nbsp;</td></tr><tr><td class="src">-&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integer">Integer</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="doc"><p>Copies from one handle to another in raw mode (using hGetContents).
Takes a function to provide progress updates to the user.</p></div></div><div class="top"><p class="src"><a name="v:hLineCopy" class="def">hLineCopy</a> :: (<a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a, <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> b) =&gt; a -&gt; b -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Copies from one handle to another in text mode (with lines).
Like <code>hBlockCopy</code>, this implementation is nice:</p><pre>hLineCopy hin hout = hLineInteract hin hout id</pre></div></div><div class="top"><p class="src"><a name="v:lineCopy" class="def">lineCopy</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Copies from <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle-FD.html#v:stdin">stdin</a></code> to <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle-FD.html#v:stdout">stdout</a></code> using lines. An alias for <code><a href="System-IO-Utils.html#v:hLineCopy">hLineCopy</a></code>
over <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle-FD.html#v:stdin">stdin</a></code> and <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle-FD.html#v:stdout">stdout</a></code>. </p></div></div><h2 id="g:3">Disk File Data Copying</h2><div class="top"><p class="src"><a name="v:copyFileLinesToFile" class="def">copyFileLinesToFile</a> :: <a href="System-IO-HVFS.html#t:FilePath">FilePath</a> -&gt; <a href="System-IO-HVFS.html#t:FilePath">FilePath</a> -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Copies one filename to another in text mode.</p><p>Please note that the Unix permission bits are set at a default; you may
need to adjust them after the copy yourself.</p><p>This function is implemented using <code><a href="System-IO-Utils.html#v:hLineCopy">hLineCopy</a></code> internally. </p></div></div><h1 id="g:4">Line Processing Utilities</h1><div class="top"><p class="src"><a name="v:hPutStrLns" class="def">hPutStrLns</a> :: <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a =&gt; a -&gt; [<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>] -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Given a list of strings, output a line containing each item, adding
newlines as appropriate. The list is not expected to have newlines already.</p></div></div><div class="top"><p class="src"><a name="v:hGetLines" class="def">hGetLines</a> :: <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a =&gt; a -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> [<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>]</p><div class="doc"><p>Given a handle, returns a list of all the lines in that handle.
Thanks to lazy evaluation, this list does not have to be read all at once.</p><p>Combined with <code><a href="System-IO-Utils.html#v:hPutStrLns">hPutStrLns</a></code>, this can make a powerful way to develop
filters. See the <code><a href="System-IO-Utils.html#v:lineInteract">lineInteract</a></code> function for more on that concept.</p><p>Example:</p><pre>main = do
l &lt;- hGetLines stdin
hPutStrLns stdout $ filter (startswith &quot;1&quot;) l</pre></div></div><h1 id="g:5">Lazy Interaction</h1><h2 id="g:6">Character-based</h2><div class="top"><p class="src"><a name="v:hInteract" class="def">hInteract</a> :: (<a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a, <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> b) =&gt; a -&gt; b -&gt; (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>) -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>This is similar to the built-in <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#v:interact">interact</a></code>, but works
on any handle, not just stdin and stdout.</p><p>In other words:</p><pre>interact = hInteract stdin stdout</pre></div></div><h2 id="g:7">Line-based</h2><div class="top"><p class="src"><a name="v:hLineInteract" class="def">hLineInteract</a> :: (<a href="System-IO-HVIO.html#t:HVIO">HVIO</a> a, <a href="System-IO-HVIO.html#t:HVIO">HVIO</a> b) =&gt; a -&gt; b -&gt; ([<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>] -&gt; [<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>]) -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Line-based interaction over arbitrary handles. This is similar
to wrapping hInteract with <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-OldList.html#v:lines">lines</a></code> and <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-OldList.html#v:unlines">unlines</a></code>.</p><p>One could view this function like this:</p><pre>hLineInteract finput foutput func =
let newf = unlines . func . lines in
hInteract finput foutput newf</pre><p>Though the actual implementation is this for efficiency:</p><pre>hLineInteract finput foutput func =
do
lines &lt;- hGetLines finput
hPutStrLns foutput (func lines)</pre></div></div><div class="top"><p class="src"><a name="v:lineInteract" class="def">lineInteract</a> :: ([<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>] -&gt; [<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>]) -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Line-based interaction. This is similar to wrapping your
interact functions with <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-OldList.html#v:lines">lines</a></code> and <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-OldList.html#v:unlines">unlines</a></code>. This equality holds:</p><pre>lineInteract = hLineInteract stdin stdout</pre><p>Here's an example:</p><pre>main = lineInteract (filter (startswith &quot;1&quot;))</pre><p>This will act as a simple version of grep -- all lines that start with 1
will be displayed; all others will be ignored.</p></div></div><h2 id="g:8">Misc. Lazy</h2><div class="top"><p class="src"><a name="v:lazyMapM" class="def">lazyMapM</a> :: (a -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> b) -&gt; [a] -&gt; <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> [b]</p><div class="doc"><p>Applies a given function to every item in a list, and returns
the new list. Unlike the system's mapM, items are evaluated lazily. </p></div></div><h1 id="g:9">Optimizations</h1><div class="top"><p class="src"><a name="v:optimizeForBatch" class="def">optimizeForBatch</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Sets stdin and stdout to be block-buffered. This can save a huge amount
of system resources since far fewer syscalls are made, and can make programs
run much faster. </p></div></div><div class="top"><p class="src"><a name="v:optimizeForInteraction" class="def">optimizeForInteraction</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Sets stdin and stdout to be line-buffered. This saves resources
on stdout, but not many on stdin, since it it still looking for newlines. </p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.16.0</p></div></body></html>