Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > eed130d744d27f25ed585ff318f1f4e2 > files > 11

ocaml-pa-monad-6.0-10.fc18.i686.rpm

<!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=iso-8859-1" http-equiv="Content-Type">
<link rel="Start" href="pa_monad.html">
<link rel="previous" href="Exception.html">
<link rel="next" href="Utest.html">
<link rel="Up" href="pa_monad.html">
<link title="Index of types" rel=Appendix href="pa_monad_types.html">
<link title="Index of exceptions" rel=Appendix href="pa_monad_exceptions.html">
<link title="Index of values" rel=Appendix href="pa_monad_values.html">
<link title="Index of modules" rel=Appendix href="pa_monad_modules.html">
<link title="Pa_monad" rel="Chapter" href="Pa_monad.html">
<link title="Cc" rel="Chapter" href="Cc.html">
<link title="Exception" rel="Chapter" href="Exception.html">
<link title="Io" rel="Chapter" href="Io.html">
<link title="Utest" rel="Chapter" href="Utest.html"><link title="IO-Monad" rel="Section" href="#3_IOMonad">
<link title="Types" rel="Subsection" href="#4_Types">
<link title="Run-Time Support" rel="Subsection" href="#4_RunTimeSupport">
<link title="Fundamental Functions" rel="Subsection" href="#4_FundamentalFunctions">
<link title="Output Functions" rel="Subsection" href="#4_OutputFunctions">
<link title="Input Functions" rel="Subsection" href="#4_InputFunctions">
<link title="General Output Functions" rel="Subsection" href="#4_GeneralOutputFunctions">
<title>Io</title>
</head>
<body>
<div class="navbar"><a class="pre" href="Exception.html" title="Exception">Previous</a>
&nbsp;<a class="up" href="pa_monad.html" title="Index">Up</a>
&nbsp;<a class="post" href="Utest.html" title="Utest">Next</a>
</div>
<h1>Module <a href="type_Io.html">Io</a></h1>
<pre><span class="keyword">module</span> Io: <code class="code">sig</code> <a href="Io.html">..</a> <code class="code">end</code></pre><div class="info">
Rudimentary I/O-monad<br>
</div>
<hr width="100%">
<br>
<h3 id="3_IOMonad">IO-Monad</h3><br>
<br>
<h4 id="4_Types">Types</h4><br>
<pre><code><span id="TYPEerror"><span class="keyword">type</span> <code class="type"></code>error</span> = </code></pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.EndOfFile"><span class="constructor">EndOfFile</span></span></code></td>
<td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Tried to read beyond end of file</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.IntOfString"><span class="constructor">IntOfString</span></span></code></td>
<td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Could not convert <code class="code">string</code> to <code class="code">int</code></td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.SysError"><span class="constructor">SysError</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>
<td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Operating system signaled an error.
                                            The <code class="code">string</code> takes the precise reason.</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td>
</tr></table>

<div class="info">
Possible errors during an IO-operation.  They are named after
    their imperative counterparts.<br>
</div>

<pre><span id="TYPEworld"><span class="keyword">type</span> <code class="type"></code>world</span> </pre>
<div class="info">
The imperative, "outside" world the <em>functional</em> IO-monad deals with.<br>
</div>

<pre><span id="TYPEeither"><span class="keyword">type</span> <code class="type">('left, 'right)</code> either</span> </pre>
<div class="info">
This type takes care of the control-flow similarly to an exception
    monad.  The <code class="code">'left</code> type is for errors, the <code class="code">'right</code> type for correct
    values.<br>
</div>

<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type">'a</code> t</span> = <code class="type"><a href="Io.html#TYPEworld">world</a> -> (<a href="Io.html#TYPEerror">error</a>, 'a) <a href="Io.html#TYPEeither">either</a> * <a href="Io.html#TYPEworld">world</a></code> </pre>
<div class="info">
An IO-monad of type <code class="code">'a</code> takes the current world and produces
    either a correct value (of type <code class="code">'a</code> or an <code class="code">error</code> and a new world.<br>
</div>

<br>
<h4 id="4_RunTimeSupport">Run-Time Support</h4><br>
<pre><span id="VAL__conjure_up"><span class="keyword">val</span> __conjure_up</span> : <code class="type">unit -> <a href="Io.html#TYPEworld">world</a></code></pre><div class="info">
<code class="code">__conjure_up ()</code>
<p>

    Conjure up a new "world".
<p>

    This function should only be used once per program.  It is best
    place in some pre-main initialization code like, for example,
    <pre class="codepre"><code class="code">        let () =
          let world = Io.__conjure_up () in
            ignore ((Io.catch (main ()) (fun _error -&gt; ...)) world)
    </code></pre>
    where we call <code class="code">main</code> with the initial world.<br>
</div>
<br>
<h4 id="4_FundamentalFunctions">Fundamental Functions</h4><br>
<pre><span id="VALbind"><span class="keyword">val</span> bind</span> : <code class="type">'a <a href="Io.html#TYPEt">t</a> -> ('a -> 'b <a href="Io.html#TYPEt">t</a>) -> 'b <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">bind an_iomonad a_function</code>
<p>

    Apply <code class="code">a_function</code> to <code class="code">an_iomonad</code> producing another IO-monad.
    <code class="code">a_function</code> takes an <code class="code">'a</code> value as argument and returns a <code class="code">'b</code>
    IO-monad.<br>
</div>
<pre><span id="VALreturn"><span class="keyword">val</span> return</span> : <code class="type">'a -> 'a <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">return a_value</code>
<p>

    List <code class="code">a_value</code> into the IO-monad.<br>
</div>
<pre><span id="VALthrow"><span class="keyword">val</span> throw</span> : <code class="type"><a href="Io.html#TYPEerror">error</a> -> 'a <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">throw an_error</code>
<p>

    Throw <code class="code">an_error</code> inside the IO-monad.<br>
</div>
<pre><span id="VALcatch"><span class="keyword">val</span> catch</span> : <code class="type">'a <a href="Io.html#TYPEt">t</a> -> (<a href="Io.html#TYPEerror">error</a> -> 'a <a href="Io.html#TYPEt">t</a>) -> 'a <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">catch an_iomonad a_handler_function</code>
<p>

    Catch IO-exceptions from <code class="code">an_iomonad</code> and feed them into
    <code class="code">a_handler_function</code>, which takes an <code class="code">error</code> value as argument and
    returns an <code class="code">'a</code> IO-monad.<br>
</div>
<br>
<h4 id="4_OutputFunctions">Output Functions</h4>
<p>

    All of these functions have exactly the same names as their imperative
    counterparts.  Moreover, they take the same arguments.<br>
<pre><span id="VALprint_char"><span class="keyword">val</span> print_char</span> : <code class="type">char -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">print_char a_character</code><br>
</div>
<pre><span id="VALprint_string"><span class="keyword">val</span> print_string</span> : <code class="type">string -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">print_string a_string</code><br>
</div>
<pre><span id="VALprint_int"><span class="keyword">val</span> print_int</span> : <code class="type">int -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">print_int an_integer</code><br>
</div>
<pre><span id="VALprint_float"><span class="keyword">val</span> print_float</span> : <code class="type">float -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">print_float a_float</code><br>
</div>
<pre><span id="VALprint_endline"><span class="keyword">val</span> print_endline</span> : <code class="type">string -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">print_endline a_string</code><br>
</div>
<pre><span id="VALprint_newline"><span class="keyword">val</span> print_newline</span> : <code class="type">unit -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">print_newline ()</code><br>
</div>
<pre><span id="VALprerr_char"><span class="keyword">val</span> prerr_char</span> : <code class="type">char -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">prerr_char a_character</code><br>
</div>
<pre><span id="VALprerr_string"><span class="keyword">val</span> prerr_string</span> : <code class="type">string -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">prerr_string a_string</code><br>
</div>
<pre><span id="VALprerr_int"><span class="keyword">val</span> prerr_int</span> : <code class="type">int -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">prerr_int an_integer</code><br>
</div>
<pre><span id="VALprerr_float"><span class="keyword">val</span> prerr_float</span> : <code class="type">float -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">prerr_float a_float</code><br>
</div>
<pre><span id="VALprerr_endline"><span class="keyword">val</span> prerr_endline</span> : <code class="type">string -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">prerr_endline a_string</code><br>
</div>
<pre><span id="VALprerr_newline"><span class="keyword">val</span> prerr_newline</span> : <code class="type">unit -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">prerr_newline ()</code><br>
</div>
<br>
<h4 id="4_InputFunctions">Input Functions</h4><br>
<pre><span id="VALread_line"><span class="keyword">val</span> read_line</span> : <code class="type">unit -> string <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">read_line ()</code><br>
</div>
<pre><span id="VALread_int"><span class="keyword">val</span> read_int</span> : <code class="type">unit -> int <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">read_int ()</code><br>
</div>
<pre><span id="VALread_float"><span class="keyword">val</span> read_float</span> : <code class="type">unit -> float <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">read_float ()</code><br>
</div>
<br>
<h4 id="4_GeneralOutputFunctions">General Output Functions</h4><br>
<pre><span id="VALopen_out"><span class="keyword">val</span> open_out</span> : <code class="type">string -> Pervasives.out_channel <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">open_out a_filename</code><br>
</div>
<pre><span id="VALoutput_char"><span class="keyword">val</span> output_char</span> : <code class="type">Pervasives.out_channel -> char -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">output_char a_channel a_char</code><br>
</div>
<pre><span id="VALoutput_string"><span class="keyword">val</span> output_string</span> : <code class="type">Pervasives.out_channel -> string -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">output_string a_channel a_string</code><br>
</div>
<pre><span id="VALclose_out"><span class="keyword">val</span> close_out</span> : <code class="type">Pervasives.out_channel -> unit <a href="Io.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">close_out a_channel</code><br>
</div>
</body></html>