mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
311 lines
No EOL
22 KiB
HTML
311 lines
No EOL
22 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<link rel="stylesheet" href="style.css" type="text/css">
|
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
<link rel="Start" href="index.html">
|
|
<link rel="previous" href="CCCat.html">
|
|
<link rel="next" href="Containers_io_is_deprecated.html">
|
|
<link rel="Up" href="index.html">
|
|
<link title="Index of types" rel=Appendix href="index_types.html">
|
|
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
|
|
<link title="Index of values" rel=Appendix href="index_values.html">
|
|
<link title="Index of class methods" rel=Appendix href="index_methods.html">
|
|
<link title="Index of class types" rel=Appendix href="index_class_types.html">
|
|
<link title="Index of modules" rel=Appendix href="index_modules.html">
|
|
<link title="Index of module types" rel=Appendix href="index_module_types.html">
|
|
<link title="CCVector" rel="Chapter" href="CCVector.html">
|
|
<link title="CCPrint" rel="Chapter" href="CCPrint.html">
|
|
<link title="CCError" rel="Chapter" href="CCError.html">
|
|
<link title="CCHeap" rel="Chapter" href="CCHeap.html">
|
|
<link title="CCList" rel="Chapter" href="CCList.html">
|
|
<link title="CCOpt" rel="Chapter" href="CCOpt.html">
|
|
<link title="CCPair" rel="Chapter" href="CCPair.html">
|
|
<link title="CCFun" rel="Chapter" href="CCFun.html">
|
|
<link title="CCHash" rel="Chapter" href="CCHash.html">
|
|
<link title="CCInt" rel="Chapter" href="CCInt.html">
|
|
<link title="CCBool" rel="Chapter" href="CCBool.html">
|
|
<link title="CCFloat" rel="Chapter" href="CCFloat.html">
|
|
<link title="CCArray" rel="Chapter" href="CCArray.html">
|
|
<link title="CCRef" rel="Chapter" href="CCRef.html">
|
|
<link title="CCSet" rel="Chapter" href="CCSet.html">
|
|
<link title="CCOrd" rel="Chapter" href="CCOrd.html">
|
|
<link title="CCRandom" rel="Chapter" href="CCRandom.html">
|
|
<link title="CCString" rel="Chapter" href="CCString.html">
|
|
<link title="CCHashtbl" rel="Chapter" href="CCHashtbl.html">
|
|
<link title="CCMap" rel="Chapter" href="CCMap.html">
|
|
<link title="CCFormat" rel="Chapter" href="CCFormat.html">
|
|
<link title="CCIO" rel="Chapter" href="CCIO.html">
|
|
<link title="CCInt64" rel="Chapter" href="CCInt64.html">
|
|
<link title="CCChar" rel="Chapter" href="CCChar.html">
|
|
<link title="CCResult" rel="Chapter" href="CCResult.html">
|
|
<link title="Containers" rel="Chapter" href="Containers.html">
|
|
<link title="CCKTree" rel="Chapter" href="CCKTree.html">
|
|
<link title="CCKList" rel="Chapter" href="CCKList.html">
|
|
<link title="CCLazy_list" rel="Chapter" href="CCLazy_list.html">
|
|
<link title="CCMultiMap" rel="Chapter" href="CCMultiMap.html">
|
|
<link title="CCMultiSet" rel="Chapter" href="CCMultiSet.html">
|
|
<link title="CCTrie" rel="Chapter" href="CCTrie.html">
|
|
<link title="CCFlatHashtbl" rel="Chapter" href="CCFlatHashtbl.html">
|
|
<link title="CCCache" rel="Chapter" href="CCCache.html">
|
|
<link title="CCPersistentHashtbl" rel="Chapter" href="CCPersistentHashtbl.html">
|
|
<link title="CCDeque" rel="Chapter" href="CCDeque.html">
|
|
<link title="CCFQueue" rel="Chapter" href="CCFQueue.html">
|
|
<link title="CCBV" rel="Chapter" href="CCBV.html">
|
|
<link title="CCMixtbl" rel="Chapter" href="CCMixtbl.html">
|
|
<link title="CCMixmap" rel="Chapter" href="CCMixmap.html">
|
|
<link title="CCRingBuffer" rel="Chapter" href="CCRingBuffer.html">
|
|
<link title="CCIntMap" rel="Chapter" href="CCIntMap.html">
|
|
<link title="CCPersistentArray" rel="Chapter" href="CCPersistentArray.html">
|
|
<link title="CCMixset" rel="Chapter" href="CCMixset.html">
|
|
<link title="CCHashconsedSet" rel="Chapter" href="CCHashconsedSet.html">
|
|
<link title="CCGraph" rel="Chapter" href="CCGraph.html">
|
|
<link title="CCHashSet" rel="Chapter" href="CCHashSet.html">
|
|
<link title="CCBitField" rel="Chapter" href="CCBitField.html">
|
|
<link title="CCHashTrie" rel="Chapter" href="CCHashTrie.html">
|
|
<link title="CCBloom" rel="Chapter" href="CCBloom.html">
|
|
<link title="CCWBTree" rel="Chapter" href="CCWBTree.html">
|
|
<link title="CCRAL" rel="Chapter" href="CCRAL.html">
|
|
<link title="CCAllocCache" rel="Chapter" href="CCAllocCache.html">
|
|
<link title="CCImmutArray" rel="Chapter" href="CCImmutArray.html">
|
|
<link title="CCHet" rel="Chapter" href="CCHet.html">
|
|
<link title="Containers_string" rel="Chapter" href="Containers_string.html">
|
|
<link title="CCKMP" rel="Chapter" href="CCKMP.html">
|
|
<link title="CCLevenshtein" rel="Chapter" href="CCLevenshtein.html">
|
|
<link title="CCApp_parse" rel="Chapter" href="CCApp_parse.html">
|
|
<link title="CCParse" rel="Chapter" href="CCParse.html">
|
|
<link title="CCBigstring" rel="Chapter" href="CCBigstring.html">
|
|
<link title="CCArray1" rel="Chapter" href="CCArray1.html">
|
|
<link title="CCPool" rel="Chapter" href="CCPool.html">
|
|
<link title="CCLock" rel="Chapter" href="CCLock.html">
|
|
<link title="CCSemaphore" rel="Chapter" href="CCSemaphore.html">
|
|
<link title="CCThread" rel="Chapter" href="CCThread.html">
|
|
<link title="CCBlockingQueue" rel="Chapter" href="CCBlockingQueue.html">
|
|
<link title="CCTimer" rel="Chapter" href="CCTimer.html">
|
|
<link title="Containers_advanced" rel="Chapter" href="Containers_advanced.html">
|
|
<link title="CCLinq" rel="Chapter" href="CCLinq.html">
|
|
<link title="CCBatch" rel="Chapter" href="CCBatch.html">
|
|
<link title="CCCat" rel="Chapter" href="CCCat.html">
|
|
<link title="CCMonadIO" rel="Chapter" href="CCMonadIO.html">
|
|
<link title="Containers_io_is_deprecated" rel="Chapter" href="Containers_io_is_deprecated.html">
|
|
<link title="CCUnix" rel="Chapter" href="CCUnix.html">
|
|
<link title="CCSexp" rel="Chapter" href="CCSexp.html">
|
|
<link title="CCSexpM" rel="Chapter" href="CCSexpM.html"><link title="Finalizers" rel="Section" href="#2_Finalizers">
|
|
<link title="Running" rel="Section" href="#2_Running">
|
|
<link title="Standard Wrappers" rel="Section" href="#2_StandardWrappers">
|
|
<link title="Standard Wrappers" rel="Section" href="#2_StandardWrappers">
|
|
<link title="Streams" rel="Section" href="#2_Streams">
|
|
<link title="Input" rel="Subsection" href="#6_Input">
|
|
<link title="Output" rel="Subsection" href="#6_Output">
|
|
<link title="File and file names" rel="Subsection" href="#6_Fileandfilenames">
|
|
<title>Containers doc : CCMonadIO</title>
|
|
</head>
|
|
<body>
|
|
<div class="navbar"><a class="pre" href="CCCat.html" title="CCCat">Previous</a>
|
|
<a class="up" href="index.html" title="Index">Up</a>
|
|
<a class="post" href="Containers_io_is_deprecated.html" title="Containers_io_is_deprecated">Next</a>
|
|
</div>
|
|
<h1>Module <a href="type_CCMonadIO.html">CCMonadIO</a></h1>
|
|
|
|
<pre><span class="keyword">module</span> CCMonadIO: <code class="code"><span class="keyword">sig</span></code> <a href="CCMonadIO.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
|
|
<h1 id="1_IOMonad">IO Monad</h1>
|
|
<p>
|
|
|
|
A simple abstraction over blocking IO, with strict evaluation. This is in
|
|
no way an alternative to Lwt/Async if you need concurrency.<br>
|
|
<b>Since</b> 0.3.3<br>
|
|
</div>
|
|
<hr width="100%">
|
|
<br>
|
|
Examples:
|
|
<p>
|
|
<ul>
|
|
<li>obtain the list of lines of a file:</li>
|
|
</ul>
|
|
|
|
<pre class="codepre"><code class="code"><span class="keyword">let</span> l = <span class="constructor">CCIO</span>.((with_in <span class="string">"/tmp/some_file"</span> >>>= read_lines) |> run_exn);;<br>
|
|
</code></pre>
|
|
<p>
|
|
<ul>
|
|
<li>transfer one file into another:</li>
|
|
</ul>
|
|
|
|
<pre class="codepre"><code class="code"><span class="keywordsign">#</span> <span class="keyword">let</span> a = <span class="constructor">CCIO</span>.(<br>
|
|
with_in <span class="string">"input"</span> >>>= <span class="keyword">fun</span> ic <span class="keywordsign">-></span><br>
|
|
with_out ~flags:[<span class="constructor">Open_creat</span>] <span class="string">"output"</span> >>>= <span class="keyword">fun</span> oc <span class="keywordsign">-></span><br>
|
|
<span class="constructor">Seq</span>.chunks 512 ic<br>
|
|
|> <span class="constructor">Seq</span>.output oc<br>
|
|
) ;;<br>
|
|
<br>
|
|
<span class="keywordsign">#</span> run a;;<br>
|
|
</code></pre><br>
|
|
|
|
<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type">'a</code> t</span> </pre>
|
|
|
|
|
|
<pre><span id="TYPEio"><span class="keyword">type</span> <code class="type">'a</code> io</span> = <code class="type">'a <a href="CCMonadIO.html#TYPEt">t</a></code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEwith_finalizer"><span class="keyword">type</span> <code class="type">'a</code> with_finalizer</span> </pre>
|
|
<div class="info ">
|
|
A value of type <code class="code"><span class="keywordsign">'</span>a with_finalizer</code> is similar to a value <code class="code"><span class="keywordsign">'</span>a t</code> but
|
|
also contains a finalizer that must be run to cleanup.
|
|
See <a href="CCMonadIO.html#VAL(>>>=)"><code class="code"><span class="constructor">CCMonadIO</span>.(>>>=)</code></a> to get rid of it.<br>
|
|
</div>
|
|
|
|
|
|
<pre><span id="TYPEor_error"><span class="keyword">type</span> <code class="type">'a</code> or_error</span> = <code class="type">[ `Error of string | `Ok of 'a ]</code> </pre>
|
|
|
|
|
|
<pre><span id="VAL(>>=)"><span class="keyword">val</span> (>>=)</span> : <code class="type">'a <a href="CCMonadIO.html#TYPEt">t</a> -> ('a -> 'b <a href="CCMonadIO.html#TYPEt">t</a>) -> 'b <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Wait for the result of an action, then use a function to build a
|
|
new action and execute it<br>
|
|
</div>
|
|
|
|
<pre><span id="VALreturn"><span class="keyword">val</span> return</span> : <code class="type">'a -> 'a <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Just return a value<br>
|
|
</div>
|
|
|
|
<pre><span id="VALrepeat"><span class="keyword">val</span> repeat</span> : <code class="type">int -> 'a <a href="CCMonadIO.html#TYPEt">t</a> -> 'a list <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Repeat an IO action as many times as required<br>
|
|
</div>
|
|
|
|
<pre><span id="VALrepeat'"><span class="keyword">val</span> repeat'</span> : <code class="type">int -> 'a <a href="CCMonadIO.html#TYPEt">t</a> -> unit <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Same as <a href="CCMonadIO.html#VALrepeat"><code class="code"><span class="constructor">CCMonadIO</span>.repeat</code></a>, but ignores the result<br>
|
|
</div>
|
|
|
|
<pre><span id="VALmap"><span class="keyword">val</span> map</span> : <code class="type">('a -> 'b) -> 'a <a href="CCMonadIO.html#TYPEt">t</a> -> 'b <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Map values<br>
|
|
</div>
|
|
|
|
<pre><span id="VAL(>|=)"><span class="keyword">val</span> (>|=)</span> : <code class="type">'a <a href="CCMonadIO.html#TYPEt">t</a> -> ('a -> 'b) -> 'b <a href="CCMonadIO.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALbind"><span class="keyword">val</span> bind</span> : <code class="type">?finalize:unit <a href="CCMonadIO.html#TYPEt">t</a> -><br> ('a -> 'b <a href="CCMonadIO.html#TYPEt">t</a>) -> 'a <a href="CCMonadIO.html#TYPEt">t</a> -> 'b <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">bind f a</code> runs the action <code class="code">a</code> and applies <code class="code">f</code> to its result
|
|
to obtain a new action. It then behaves exactly like this new
|
|
action.<br>
|
|
</div>
|
|
<div class="param_info"><code class="code">finalize</code> : an optional action that is always run after evaluating
|
|
the whole action</div>
|
|
|
|
<pre><span id="VALpure"><span class="keyword">val</span> pure</span> : <code class="type">'a -> 'a <a href="CCMonadIO.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VAL(<*>)"><span class="keyword">val</span> (<*>)</span> : <code class="type">('a -> 'b) <a href="CCMonadIO.html#TYPEt">t</a> -> 'a <a href="CCMonadIO.html#TYPEt">t</a> -> 'b <a href="CCMonadIO.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALlift"><span class="keyword">val</span> lift</span> : <code class="type">('a -> 'b) -> 'a <a href="CCMonadIO.html#TYPEt">t</a> -> 'b <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Synonym to <a href="CCMonadIO.html#VALmap"><code class="code"><span class="constructor">CCMonadIO</span>.map</code></a><br>
|
|
</div>
|
|
|
|
<pre><span id="VALlift2"><span class="keyword">val</span> lift2</span> : <code class="type">('a -> 'b -> 'c) -> 'a <a href="CCMonadIO.html#TYPEt">t</a> -> 'b <a href="CCMonadIO.html#TYPEt">t</a> -> 'c <a href="CCMonadIO.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALlift3"><span class="keyword">val</span> lift3</span> : <code class="type">('a -> 'b -> 'c -> 'd) -><br> 'a <a href="CCMonadIO.html#TYPEt">t</a> -> 'b <a href="CCMonadIO.html#TYPEt">t</a> -> 'c <a href="CCMonadIO.html#TYPEt">t</a> -> 'd <a href="CCMonadIO.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALsequence"><span class="keyword">val</span> sequence</span> : <code class="type">'a <a href="CCMonadIO.html#TYPEt">t</a> list -> 'a list <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Runs operations one by one and gather their results<br>
|
|
</div>
|
|
|
|
<pre><span id="VALsequence_map"><span class="keyword">val</span> sequence_map</span> : <code class="type">('a -> 'b <a href="CCMonadIO.html#TYPEt">t</a>) -> 'a list -> 'b list <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Generalization of <a href="CCMonadIO.html#VALsequence"><code class="code"><span class="constructor">CCMonadIO</span>.sequence</code></a><br>
|
|
</div>
|
|
|
|
<pre><span id="VALfail"><span class="keyword">val</span> fail</span> : <code class="type">string -> 'a <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">fail msg</code> fails with the given message. Running the IO value will
|
|
return an <code class="code"><span class="keywordsign">`</span><span class="constructor">Error</span></code> variant<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_Finalizers">Finalizers</h2><br>
|
|
|
|
<pre><span id="VAL(>>>=)"><span class="keyword">val</span> (>>>=)</span> : <code class="type">'a <a href="CCMonadIO.html#TYPEwith_finalizer">with_finalizer</a> -> ('a -> 'b <a href="CCMonadIO.html#TYPEt">t</a>) -> 'b <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Same as <a href="CCMonadIO.html#VAL(>>=)"><code class="code"><span class="constructor">CCMonadIO</span>.(>>=)</code></a>, but taking the finalizer into account. Once this
|
|
IO value is done executing, the finalizer is executed and the resource,
|
|
fred.<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_Running">Running</h2><br>
|
|
|
|
<pre><span id="VALrun"><span class="keyword">val</span> run</span> : <code class="type">'a <a href="CCMonadIO.html#TYPEt">t</a> -> 'a <a href="CCMonadIO.html#TYPEor_error">or_error</a></code></pre><div class="info ">
|
|
Run an IO action.<br>
|
|
<b>Returns</b> either <code class="code"><span class="keywordsign">`</span><span class="constructor">Ok</span> x</code> when <code class="code">x</code> is the successful result of the
|
|
computation, or some <code class="code"><span class="keywordsign">`</span><span class="constructor">Error</span> <span class="string">"message"</span></code><br>
|
|
</div>
|
|
|
|
<pre><span id="EXCEPTIONIO_error"><span class="keyword">exception</span> IO_error</span> <span class="keyword">of</span> <code class="type">string</code></pre>
|
|
|
|
<pre><span id="VALrun_exn"><span class="keyword">val</span> run_exn</span> : <code class="type">'a <a href="CCMonadIO.html#TYPEt">t</a> -> 'a</code></pre><div class="info ">
|
|
Unsafe version of <a href="CCMonadIO.html#VALrun"><code class="code"><span class="constructor">CCMonadIO</span>.run</code></a>. It assumes non-failure.<br>
|
|
<b>Raises</b> <code>IO_error</code> if the execution didn't go well<br>
|
|
</div>
|
|
|
|
<pre><span id="VALregister_printer"><span class="keyword">val</span> register_printer</span> : <code class="type">(exn -> string option) -> unit</code></pre><div class="info ">
|
|
<code class="code">register_printer p</code> register <code class="code">p</code> as a possible failure printer.
|
|
If <code class="code">run a</code> raises an exception <code class="code">e</code>, <code class="code">p e</code> is evaluated. If <code class="code">p e = <span class="constructor">Some</span> msg</code>
|
|
then the error message will be <code class="code">msg</code>, otherwise other printers will
|
|
be tried<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_StandardWrappers">Standard Wrappers</h2><br>
|
|
<br>
|
|
<h2 id="2_StandardWrappers">Standard Wrappers</h2><br>
|
|
<br>
|
|
<h6 id="6_Input">Input</h6><br>
|
|
|
|
<pre><span id="VALwith_in"><span class="keyword">val</span> with_in</span> : <code class="type">?mode:int -><br> ?flags:Pervasives.open_flag list -><br> string -> Pervasives.in_channel <a href="CCMonadIO.html#TYPEwith_finalizer">with_finalizer</a></code></pre><div class="info ">
|
|
Open an input file with the given optional flag list.
|
|
It yields a <code class="code">in_channel</code> with a finalizer attached. See <a href="CCMonadIO.html#VAL(>>>=)"><code class="code"><span class="constructor">CCMonadIO</span>.(>>>=)</code></a> to
|
|
use it.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALread"><span class="keyword">val</span> read</span> : <code class="type">Pervasives.in_channel -> Bytes.t -> int -> int -> int <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Read a chunk into the given string<br>
|
|
</div>
|
|
|
|
<pre><span id="VALread_line"><span class="keyword">val</span> read_line</span> : <code class="type">Pervasives.in_channel -> string option <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Read a line from the channel. Returns <code class="code"><span class="constructor">None</span></code> if the input is terminated.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALread_lines"><span class="keyword">val</span> read_lines</span> : <code class="type">Pervasives.in_channel -> string list <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Read all lines eagerly<br>
|
|
</div>
|
|
|
|
<pre><span id="VALread_all"><span class="keyword">val</span> read_all</span> : <code class="type">Pervasives.in_channel -> string <a href="CCMonadIO.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Read the whole channel into a buffer, then converted into a string<br>
|
|
</div>
|
|
<br>
|
|
<h6 id="6_Output">Output</h6><br>
|
|
|
|
<pre><span id="VALwith_out"><span class="keyword">val</span> with_out</span> : <code class="type">?mode:int -><br> ?flags:Pervasives.open_flag list -><br> string -> Pervasives.out_channel <a href="CCMonadIO.html#TYPEwith_finalizer">with_finalizer</a></code></pre><div class="info ">
|
|
Same as <a href="CCMonadIO.html#VALwith_in"><code class="code"><span class="constructor">CCMonadIO</span>.with_in</code></a> but for an output channel<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwith_out_a"><span class="keyword">val</span> with_out_a</span> : <code class="type">?mode:int -><br> ?flags:Pervasives.open_flag list -><br> string -> Pervasives.out_channel <a href="CCMonadIO.html#TYPEwith_finalizer">with_finalizer</a></code></pre><div class="info ">
|
|
Similar to <a href="CCMonadIO.html#VALwith_out"><code class="code"><span class="constructor">CCMonadIO</span>.with_out</code></a> but with the <code class="code"><span class="constructor">Open_append</span></code> and <code class="code"><span class="constructor">Open_creat</span></code>
|
|
flags activated<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwrite"><span class="keyword">val</span> write</span> : <code class="type">Pervasives.out_channel -> string -> int -> int -> unit <a href="CCMonadIO.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALwrite_str"><span class="keyword">val</span> write_str</span> : <code class="type">Pervasives.out_channel -> string -> unit <a href="CCMonadIO.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALwrite_buf"><span class="keyword">val</span> write_buf</span> : <code class="type">Pervasives.out_channel -> Buffer.t -> unit <a href="CCMonadIO.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALwrite_line"><span class="keyword">val</span> write_line</span> : <code class="type">Pervasives.out_channel -> string -> unit <a href="CCMonadIO.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALflush"><span class="keyword">val</span> flush</span> : <code class="type">Pervasives.out_channel -> unit <a href="CCMonadIO.html#TYPEt">t</a></code></pre><br>
|
|
<h2 id="2_Streams">Streams</h2>
|
|
<p>
|
|
|
|
Iterators on chunks of bytes, or lines, or any other value using combinators.
|
|
Those iterators are usable only once, because their source might
|
|
be usable only once (think of a socket)<br>
|
|
|
|
<pre><span class="keyword">module</span> <a href="CCMonadIO.Seq.html">Seq</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCMonadIO.Seq.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><br>
|
|
<h6 id="6_Fileandfilenames">File and file names</h6>
|
|
<p>
|
|
|
|
How to list recursively files in a directory:
|
|
<pre class="codepre"><code class="code"> <span class="constructor">CCIO</span>.(<br>
|
|
<span class="constructor">File</span>.read_dir ~recurse:<span class="keyword">true</span> (<span class="constructor">File</span>.make <span class="string">"/tmp"</span>)<br>
|
|
>>= <span class="constructor">Seq</span>.output ~sep:<span class="string">"\n"</span> stdout<br>
|
|
) |> <span class="constructor">CCIO</span>.run_exn ;;<br>
|
|
<br>
|
|
</code></pre>
|
|
<p>
|
|
|
|
See <a href="CCMonadIO.File.html#VALwalk"><code class="code"><span class="constructor">CCMonadIO</span>.<span class="constructor">File</span>.walk</code></a> if you also need to list directories.<br>
|
|
|
|
<pre><span class="keyword">module</span> <a href="CCMonadIO.File.html">File</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCMonadIO.File.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
|
|
<pre><span class="keyword">module</span> <a href="CCMonadIO.Raw.html">Raw</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCMonadIO.Raw.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info">
|
|
Low level access
|
|
</div>
|
|
</body></html> |