/usr/share/doc/liblwt-ocaml-dev/api/Pa_lwt.html is in liblwt-ocaml-doc 2.4.3-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | <!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="index.html">
<link rel="previous" href="Lwt_bytes.html">
<link rel="next" href="Pa_lwt_log.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 attributes" rel=Appendix href="index_attributes.html">
<link title="Index of class methods" rel=Appendix href="index_methods.html">
<link title="Index of classes" rel=Appendix href="index_classes.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="Lwt_condition" rel="Chapter" href="Lwt_condition.html">
<link title="Lwt_list" rel="Chapter" href="Lwt_list.html">
<link title="Lwt" rel="Chapter" href="Lwt.html">
<link title="Lwt_mutex" rel="Chapter" href="Lwt_mutex.html">
<link title="Lwt_mvar" rel="Chapter" href="Lwt_mvar.html">
<link title="Lwt_pool" rel="Chapter" href="Lwt_pool.html">
<link title="Lwt_sequence" rel="Chapter" href="Lwt_sequence.html">
<link title="Lwt_stream" rel="Chapter" href="Lwt_stream.html">
<link title="Lwt_switch" rel="Chapter" href="Lwt_switch.html">
<link title="Lwt_util" rel="Chapter" href="Lwt_util.html">
<link title="Lwt_pqueue" rel="Chapter" href="Lwt_pqueue.html">
<link title="Lwt_lib" rel="Chapter" href="Lwt_lib.html">
<link title="Lwt_glib" rel="Chapter" href="Lwt_glib.html">
<link title="Lwt_preemptive" rel="Chapter" href="Lwt_preemptive.html">
<link title="Lwt_event" rel="Chapter" href="Lwt_event.html">
<link title="Lwt_signal" rel="Chapter" href="Lwt_signal.html">
<link title="Lwt_react" rel="Chapter" href="Lwt_react.html">
<link title="Lwt_ssl" rel="Chapter" href="Lwt_ssl.html">
<link title="Lwt_text" rel="Chapter" href="Lwt_text.html">
<link title="Lwt_term" rel="Chapter" href="Lwt_term.html">
<link title="Lwt_read_line" rel="Chapter" href="Lwt_read_line.html">
<link title="Lwt_top" rel="Chapter" href="Lwt_top.html">
<link title="Lwt_chan" rel="Chapter" href="Lwt_chan.html">
<link title="Lwt_daemon" rel="Chapter" href="Lwt_daemon.html">
<link title="Lwt_gc" rel="Chapter" href="Lwt_gc.html">
<link title="Lwt_io" rel="Chapter" href="Lwt_io.html">
<link title="Lwt_log" rel="Chapter" href="Lwt_log.html">
<link title="Lwt_main" rel="Chapter" href="Lwt_main.html">
<link title="Lwt_process" rel="Chapter" href="Lwt_process.html">
<link title="Lwt_throttle" rel="Chapter" href="Lwt_throttle.html">
<link title="Lwt_timeout" rel="Chapter" href="Lwt_timeout.html">
<link title="Lwt_unix" rel="Chapter" href="Lwt_unix.html">
<link title="Lwt_sys" rel="Chapter" href="Lwt_sys.html">
<link title="Lwt_engine" rel="Chapter" href="Lwt_engine.html">
<link title="Lwt_bytes" rel="Chapter" href="Lwt_bytes.html">
<link title="Pa_lwt" rel="Chapter" href="Pa_lwt.html">
<link title="Pa_lwt_log" rel="Chapter" href="Pa_lwt_log.html"><title>Pa_lwt</title>
</head>
<body>
<div class="navbar"><a class="pre" href="Lwt_bytes.html" title="Lwt_bytes">Previous</a>
<a class="up" href="index.html" title="Index">Up</a>
<a class="post" href="Pa_lwt_log.html" title="Pa_lwt_log">Next</a>
</div>
<h1>Module <a href="type_Pa_lwt.html">Pa_lwt</a></h1>
<pre><span class="keyword">module</span> Pa_lwt: <code class="code"><span class="keyword">sig</span></code> <a href="Pa_lwt.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
Syntactic sugars for lwt<br>
</div>
<hr width="100%">
<br>
This extension add the following sugars:
<p>
<ul>
<li>anonymous bind:</li>
</ul>
<pre class="codepre"><code class="code"> write stdio <span class="string">"Hello, "</span> >> write stdio <span class="string">"world!"</span><br>
</code></pre>
<p>
<ul>
<li>lwt-binding:</li>
</ul>
<pre class="codepre"><code class="code"> lwt ch = get_char stdin <span class="keyword">in</span><br>
code<br>
</code></pre>
<p>
is the same as <code class="code">bind (get_char stdin) (<span class="keyword">fun</span> ch <span class="keywordsign">-></span> code)</code>
<p>
Moreover it supports parallel binding:
<p>
<pre class="codepre"><code class="code"> lwt x = do_something1 ()<br>
<span class="keyword">and</span> y = do_something2 <span class="keyword">in</span><br>
code<br>
</code></pre>
<p>
will let <code class="code">do_something1 ()</code> and <code class="code">do_something2 ()</code> runs then
bind their result to <code class="code">x</code> and <code class="code">y</code>. It is the same as:
<p>
<pre class="codepre"><code class="code"> <span class="keyword">let</span> t1 = do_something1<br>
<span class="keyword">and</span> t2 = do_something2 <span class="keyword">in</span><br>
bind t1 (<span class="keyword">fun</span> x <span class="keywordsign">-></span> bind t2 (<span class="keyword">fun</span> y <span class="keywordsign">-></span> code))<br>
</code></pre>
<p>
<ul>
<li>exception catching:</li>
</ul>
<pre class="codepre"><code class="code"> try_lwt<br>
<expr><br>
</code></pre>,
<p>
<pre class="codepre"><code class="code"> try_lwt<br>
<expr><br>
<span class="keyword">with</span><br>
<branches><br>
</code></pre>,
<p>
<pre class="codepre"><code class="code"> try_lwt<br>
<expr><br>
finally<br>
<expr><br>
</code></pre>
<p>
and:
<p>
<pre class="codepre"><code class="code"> try_lwt<br>
<expr><br>
<span class="keyword">with</span><br>
<branches><br>
finally<br>
<expr><br>
</code></pre>
<p>
For example:
<p>
<pre class="codepre"><code class="code"> try_lwt<br>
f x<br>
<span class="keyword">with</span><br>
<span class="keywordsign">|</span> <span class="constructor">Failure</span> msg <span class="keywordsign">-></span><br>
prerr_endline msg;<br>
return ()<br>
</code></pre>
<p>
is expanded to:
<p>
<pre class="codepre"><code class="code"> catch (<span class="keyword">fun</span> _ <span class="keywordsign">-></span> f x)<br>
(<span class="keyword">function</span><br>
<span class="keywordsign">|</span> <span class="constructor">Failure</span> msg <span class="keywordsign">-></span><br>
prerr_endline msg;<br>
return ()<br>
<span class="keywordsign">|</span> exn <span class="keywordsign">-></span><br>
<span class="constructor">Lwt</span>.fail exn)<br>
</code></pre>
<p>
Note that the <code class="code">exn <span class="keywordsign">-></span> <span class="constructor">Lwt</span>.fail exn</code> branch is automatically addedd
when needed.
<p>
The construction <code class="code">try_lwt <expr></code> just catch regular exception
into lwt exception. i.e. it is the same as <code class="code">catch (<span class="keyword">fun</span> _ <span class="keywordsign">-></span> <expr>) fail</code>.
<p>
<ul>
<li>exception raising:</li>
</ul>
<pre class="codepre"><code class="code"> raise_lwt <expr><br>
</code></pre>
<p>
This allow exception to be traced when the -lwt-debug switch is passed
to the syntax extension.
<p>
<ul>
<li>assertion:</li>
</ul>
<pre class="codepre"><code class="code"> assert_lwt <expr><br>
</code></pre>
<p>
<ul>
<li>for loop:</li>
</ul>
<pre class="codepre"><code class="code"> for_lwt i = <expr> <span class="keyword">to</span> <expr> <span class="keyword">do</span><br>
<expr><br>
<span class="keyword">done</span><br>
</code></pre>
<p>
and:
<p>
<pre class="codepre"><code class="code"> for_lwt i = <expr> <span class="keyword">downto</span> <expr> <span class="keyword">do</span><br>
<expr><br>
<span class="keyword">done</span><br>
</code></pre>
<p>
<ul>
<li>iteration over streams:</li>
</ul>
<pre class="codepre"><code class="code"> for_lwt <patt> <span class="keyword">in</span> <expr> <span class="keyword">do</span><br>
<expr><br>
<span class="keyword">done</span><br>
</code></pre>
<p>
<ul>
<li>while loop:</li>
</ul>
<pre class="codepre"><code class="code"> while_lwt <expr> <span class="keyword">do</span><br>
<expr><br>
<span class="keyword">done</span><br>
</code></pre>
<p>
<ul>
<li>pattern mattching:</li>
</ul>
<pre class="codepre"><code class="code"> match_lwt <expr> <span class="keyword">with</span><br>
<span class="keywordsign">|</span> <patt_1> <span class="keywordsign">-></span> <expr_1><br>
...<br>
<span class="keywordsign">|</span> <patt_n> <span class="keywordsign">-></span> <expr_n><br>
</code></pre><br>
</body></html>
|