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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
<!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">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="Start" href="index.html">
<link rel="previous" href="Longident.html">
<link rel="next" href="Numbers.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 modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="Arg_helper" rel="Chapter" href="Arg_helper.html">
<link title="Ast_helper" rel="Chapter" href="Ast_helper.html">
<link title="Ast_invariants" rel="Chapter" href="Ast_invariants.html">
<link title="Ast_iterator" rel="Chapter" href="Ast_iterator.html">
<link title="Ast_mapper" rel="Chapter" href="Ast_mapper.html">
<link title="Asttypes" rel="Chapter" href="Asttypes.html">
<link title="Attr_helper" rel="Chapter" href="Attr_helper.html">
<link title="Build_path_prefix_map" rel="Chapter" href="Build_path_prefix_map.html">
<link title="Builtin_attributes" rel="Chapter" href="Builtin_attributes.html">
<link title="CamlinternalMenhirLib" rel="Chapter" href="CamlinternalMenhirLib.html">
<link title="Ccomp" rel="Chapter" href="Ccomp.html">
<link title="Clflags" rel="Chapter" href="Clflags.html">
<link title="Compiler_libs" rel="Chapter" href="Compiler_libs.html">
<link title="Config" rel="Chapter" href="Config.html">
<link title="Consistbl" rel="Chapter" href="Consistbl.html">
<link title="Depend" rel="Chapter" href="Depend.html">
<link title="Docstrings" rel="Chapter" href="Docstrings.html">
<link title="Domainstate" rel="Chapter" href="Domainstate.html">
<link title="Identifiable" rel="Chapter" href="Identifiable.html">
<link title="Int_replace_polymorphic_compare" rel="Chapter" href="Int_replace_polymorphic_compare.html">
<link title="Lexer" rel="Chapter" href="Lexer.html">
<link title="Load_path" rel="Chapter" href="Load_path.html">
<link title="Location" rel="Chapter" href="Location.html">
<link title="Longident" rel="Chapter" href="Longident.html">
<link title="Misc" rel="Chapter" href="Misc.html">
<link title="Numbers" rel="Chapter" href="Numbers.html">
<link title="Parse" rel="Chapter" href="Parse.html">
<link title="Parser" rel="Chapter" href="Parser.html">
<link title="Parsetree" rel="Chapter" href="Parsetree.html">
<link title="Pparse" rel="Chapter" href="Pparse.html">
<link title="Pprintast" rel="Chapter" href="Pprintast.html">
<link title="Printast" rel="Chapter" href="Printast.html">
<link title="Profile" rel="Chapter" href="Profile.html">
<link title="Strongly_connected_components" rel="Chapter" href="Strongly_connected_components.html">
<link title="Syntaxerr" rel="Chapter" href="Syntaxerr.html">
<link title="Targetint" rel="Chapter" href="Targetint.html">
<link title="Terminfo" rel="Chapter" href="Terminfo.html">
<link title="Warnings" rel="Chapter" href="Warnings.html"><title>Misc</title>
</head>
<body>
<div class="navbar"><a class="pre" href="Longident.html" title="Longident">Previous</a>
<a class="up" href="index.html" title="Index">Up</a>
<a class="post" href="Numbers.html" title="Numbers">Next</a>
</div>
<h1>Module <a href="type_Misc.html">Misc</a></h1>
<pre><span id="MODULEMisc"><span class="keyword">module</span> Misc</span>: <code class="code"><span class="keyword">sig</span></code> <a href="Misc.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
<div class="info-desc">
<p>Miscellaneous useful types and functions</p>
<p><b>Warning:</b> this module is unstable and part of
<a href="Compiler_libs.html">compiler-libs</a>.</p>
</div>
</div>
<hr width="100%">
<pre><span id="VALfatal_error"><span class="keyword">val</span> fatal_error</span> : <code class="type">string -> 'a</code></pre>
<pre><span id="VALfatal_errorf"><span class="keyword">val</span> fatal_errorf</span> : <code class="type">('a, Format.formatter, unit, 'b) format4 -> 'a</code></pre>
<pre><span id="EXCEPTIONFatal_error"><span class="keyword">exception</span> Fatal_error</span></pre>
<pre><span id="VALtry_finally"><span class="keyword">val</span> try_finally</span> : <code class="type">?always:(unit -> unit) -> ?exceptionally:(unit -> unit) -> (unit -> 'a) -> 'a</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">try_finally work ~always ~exceptionally</code> is designed to run code
in <code class="code">work</code> that may fail with an exception, and has two kind of
cleanup routines: <code class="code">always</code>, that must be run after any execution
of the function (typically, freeing system resources), and
<code class="code">exceptionally</code>, that should be run only if <code class="code">work</code> or <code class="code">always</code>
failed with an exception (typically, undoing user-visible state
changes that would only make sense if the function completes
correctly). For example:</p>
<pre class="codepre"><code class="code"> <span class="keyword">let</span> objfile = outputprefix ^ <span class="string">".cmo"</span> <span class="keyword">in</span>
<span class="keyword">let</span> oc = open_out_bin objfile <span class="keyword">in</span>
<span class="constructor">Misc</span>.try_finally
(<span class="keyword">fun</span> () <span class="keywordsign">-></span>
bytecode
++ <span class="constructor">Timings</span>.(accumulate_time (<span class="constructor">Generate</span> sourcefile))
(<span class="constructor">Emitcode</span>.to_file oc modulename objfile);
<span class="constructor">Warnings</span>.check_fatal ())
~always:(<span class="keyword">fun</span> () <span class="keywordsign">-></span> close_out oc)
~exceptionally:(<span class="keyword">fun</span> _exn <span class="keywordsign">-></span> remove_file objfile);
</code></pre>
<p>If <code class="code">exceptionally</code> fail with an exception, it is propagated as
usual.</p>
<p>If <code class="code">always</code> or <code class="code">exceptionally</code> use exceptions internally for
control-flow but do not raise, then <code class="code">try_finally</code> is careful to
preserve any exception backtrace coming from <code class="code">work</code> or <code class="code">always</code>
for easier debugging.</p>
</div>
</div>
<pre><span id="VALmap_end"><span class="keyword">val</span> map_end</span> : <code class="type">('a -> 'b) -> 'a list -> 'b list -> 'b list</code></pre>
<pre><span id="VALmap_left_right"><span class="keyword">val</span> map_left_right</span> : <code class="type">('a -> 'b) -> 'a list -> 'b list</code></pre>
<pre><span id="VALfor_all2"><span class="keyword">val</span> for_all2</span> : <code class="type">('a -> 'b -> bool) -> 'a list -> 'b list -> bool</code></pre>
<pre><span id="VALreplicate_list"><span class="keyword">val</span> replicate_list</span> : <code class="type">'a -> int -> 'a list</code></pre>
<pre><span id="VALlist_remove"><span class="keyword">val</span> list_remove</span> : <code class="type">'a -> 'a list -> 'a list</code></pre>
<pre><span id="VALsplit_last"><span class="keyword">val</span> split_last</span> : <code class="type">'a list -> 'a list * 'a</code></pre>
<pre><code><span id="TYPEref_and_value"><span class="keyword">type</span> <code class="type"></code>ref_and_value</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="TYPEELTref_and_value.R"><span class="constructor">R</span></span> <span class="keyword">:</span> <code class="type">'a ref * 'a</code> <span class="keyword">-></span> <code class="type"><a href="Misc.html#TYPEref_and_value">ref_and_value</a></code></code></td>
</tr></table>
<pre><span id="VALprotect_refs"><span class="keyword">val</span> protect_refs</span> : <code class="type"><a href="Misc.html#TYPEref_and_value">ref_and_value</a> list -> (unit -> 'a) -> 'a</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">protect_refs l f</code> temporarily sets <code class="code">r</code> to <code class="code">v</code> for each <code class="code"><span class="constructor">R</span> (r, v)</code> in <code class="code">l</code>
while executing <code class="code">f</code>. The previous contents of the references is restored
even if <code class="code">f</code> raises an exception, without altering the exception backtrace.</p>
</div>
</div>
<pre><span id="MODULEStdlib"><span class="keyword">module</span> <a href="Misc.Stdlib.html">Stdlib</a></span>: <code class="code"><span class="keyword">sig</span></code> <a href="Misc.Stdlib.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span id="VALfind_in_path"><span class="keyword">val</span> find_in_path</span> : <code class="type">string list -> string -> string</code></pre>
<pre><span id="VALfind_in_path_rel"><span class="keyword">val</span> find_in_path_rel</span> : <code class="type">string list -> string -> string</code></pre>
<pre><span id="VALfind_in_path_uncap"><span class="keyword">val</span> find_in_path_uncap</span> : <code class="type">string list -> string -> string</code></pre>
<pre><span id="VALremove_file"><span class="keyword">val</span> remove_file</span> : <code class="type">string -> unit</code></pre>
<pre><span id="VALexpand_directory"><span class="keyword">val</span> expand_directory</span> : <code class="type">string -> string -> string</code></pre>
<pre><span id="VALsplit_path_contents"><span class="keyword">val</span> split_path_contents</span> : <code class="type">?sep:char -> string -> string list</code></pre>
<pre><span id="VALcreate_hashtable"><span class="keyword">val</span> create_hashtable</span> : <code class="type">int -> ('a * 'b) list -> ('a, 'b) Hashtbl.t</code></pre>
<pre><span id="VALcopy_file"><span class="keyword">val</span> copy_file</span> : <code class="type">in_channel -> out_channel -> unit</code></pre>
<pre><span id="VALcopy_file_chunk"><span class="keyword">val</span> copy_file_chunk</span> : <code class="type">in_channel -> out_channel -> int -> unit</code></pre>
<pre><span id="VALstring_of_file"><span class="keyword">val</span> string_of_file</span> : <code class="type">in_channel -> string</code></pre>
<pre><span id="VALoutput_to_file_via_temporary"><span class="keyword">val</span> output_to_file_via_temporary</span> : <code class="type">?mode:open_flag list -><br> string -> (string -> out_channel -> 'a) -> 'a</code></pre>
<pre><span id="VALprotect_writing_to_file"><span class="keyword">val</span> protect_writing_to_file</span> : <code class="type">filename:string -> f:(out_channel -> 'a) -> 'a</code></pre><div class="info ">
<div class="info-desc">
<p>Open the given <code class="code">filename</code> for writing (in binary mode), pass the
<code class="code">out_channel</code> to the given function, then close the channel. If the function
raises an exception then <code class="code">filename</code> will be removed.</p>
</div>
</div>
<pre><span id="VALlog2"><span class="keyword">val</span> log2</span> : <code class="type">int -> int</code></pre>
<pre><span id="VALalign"><span class="keyword">val</span> align</span> : <code class="type">int -> int -> int</code></pre>
<pre><span id="VALno_overflow_add"><span class="keyword">val</span> no_overflow_add</span> : <code class="type">int -> int -> bool</code></pre>
<pre><span id="VALno_overflow_sub"><span class="keyword">val</span> no_overflow_sub</span> : <code class="type">int -> int -> bool</code></pre>
<pre><span id="VALno_overflow_mul"><span class="keyword">val</span> no_overflow_mul</span> : <code class="type">int -> int -> bool</code></pre>
<pre><span id="VALno_overflow_lsl"><span class="keyword">val</span> no_overflow_lsl</span> : <code class="type">int -> int -> bool</code></pre>
<pre><span id="MODULEInt_literal_converter"><span class="keyword">module</span> <a href="Misc.Int_literal_converter.html">Int_literal_converter</a></span>: <code class="code"><span class="keyword">sig</span></code> <a href="Misc.Int_literal_converter.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span id="VALchop_extensions"><span class="keyword">val</span> chop_extensions</span> : <code class="type">string -> string</code></pre>
<pre><span id="VALsearch_substring"><span class="keyword">val</span> search_substring</span> : <code class="type">string -> string -> int -> int</code></pre>
<pre><span id="VALreplace_substring"><span class="keyword">val</span> replace_substring</span> : <code class="type">before:string -> after:string -> string -> string</code></pre>
<pre><span id="VALrev_split_words"><span class="keyword">val</span> rev_split_words</span> : <code class="type">string -> string list</code></pre>
<pre><span id="VALget_ref"><span class="keyword">val</span> get_ref</span> : <code class="type">'a list ref -> 'a list</code></pre>
<pre><span id="VALset_or_ignore"><span class="keyword">val</span> set_or_ignore</span> : <code class="type">('a -> 'b option) -> 'b option ref -> 'a -> unit</code></pre>
<pre><span id="VALfst3"><span class="keyword">val</span> fst3</span> : <code class="type">'a * 'b * 'c -> 'a</code></pre>
<pre><span id="VALsnd3"><span class="keyword">val</span> snd3</span> : <code class="type">'a * 'b * 'c -> 'b</code></pre>
<pre><span id="VALthd3"><span class="keyword">val</span> thd3</span> : <code class="type">'a * 'b * 'c -> 'c</code></pre>
<pre><span id="VALfst4"><span class="keyword">val</span> fst4</span> : <code class="type">'a * 'b * 'c * 'd -> 'a</code></pre>
<pre><span id="VALsnd4"><span class="keyword">val</span> snd4</span> : <code class="type">'a * 'b * 'c * 'd -> 'b</code></pre>
<pre><span id="VALthd4"><span class="keyword">val</span> thd4</span> : <code class="type">'a * 'b * 'c * 'd -> 'c</code></pre>
<pre><span id="VALfor4"><span class="keyword">val</span> for4</span> : <code class="type">'a * 'b * 'c * 'd -> 'd</code></pre>
<pre><span id="MODULELongString"><span class="keyword">module</span> <a href="Misc.LongString.html">LongString</a></span>: <code class="code"><span class="keyword">sig</span></code> <a href="Misc.LongString.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span id="VALedit_distance"><span class="keyword">val</span> edit_distance</span> : <code class="type">string -> string -> int -> int option</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">edit_distance a b cutoff</code> computes the edit distance between
strings <code class="code">a</code> and <code class="code">b</code>. To help efficiency, it uses a cutoff: if the
distance <code class="code">d</code> is smaller than <code class="code">cutoff</code>, it returns <code class="code"><span class="constructor">Some</span> d</code>, else
<code class="code"><span class="constructor">None</span></code>.</p>
<p>The distance algorithm currently used is Damerau-Levenshtein: it
computes the number of insertion, deletion, substitution of
letters, or swapping of adjacent letters to go from one word to the
other. The particular algorithm may change in the future.</p>
</div>
</div>
<pre><span id="VALspellcheck"><span class="keyword">val</span> spellcheck</span> : <code class="type">string list -> string -> string list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">spellcheck env name</code> takes a list of names <code class="code">env</code> that exist in
the current environment and an erroneous <code class="code">name</code>, and returns a
list of suggestions taken from <code class="code">env</code>, that are close enough to
<code class="code">name</code> that it may be a typo for one of them.</p>
</div>
</div>
<pre><span id="VALdid_you_mean"><span class="keyword">val</span> did_you_mean</span> : <code class="type">Format.formatter -> (unit -> string list) -> unit</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">did_you_mean ppf get_choices</code> hints that the user may have meant
one of the option returned by calling <code class="code">get_choices</code>. It does nothing
if the returned list is empty.</p>
<p>The <code class="code">unit <span class="keywordsign">-></span> ...</code> thunking is meant to delay any potentially-slow
computation (typically computing edit-distance with many things
from the current environment) to when the hint message is to be
printed. You should print an understandable error message before
calling <code class="code">did_you_mean</code>, so that users get a clear notification of
the failure even if producing the hint is slow.</p>
</div>
</div>
<pre><span id="VALcut_at"><span class="keyword">val</span> cut_at</span> : <code class="type">string -> char -> string * string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">String</span>.cut_at s c</code> returns a pair containing the sub-string before
the first occurrence of <code class="code">c</code> in <code class="code">s</code>, and the sub-string after the
first occurrence of <code class="code">c</code> in <code class="code">s</code>.
<code class="code"><span class="keyword">let</span> (before, after) = <span class="constructor">String</span>.cut_at s c <span class="keyword">in</span><br>
before ^ <span class="constructor">String</span>.make 1 c ^ after</code> is the identity if <code class="code">s</code> contains <code class="code">c</code>.</p>
<p>Raise <code class="code"><span class="constructor">Not_found</span></code> if the character does not appear in the string</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.01</li>
</ul>
</div>
<pre><span id="MODULEColor"><span class="keyword">module</span> <a href="Misc.Color.html">Color</a></span>: <code class="code"><span class="keyword">sig</span></code> <a href="Misc.Color.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span id="MODULEError_style"><span class="keyword">module</span> <a href="Misc.Error_style.html">Error_style</a></span>: <code class="code"><span class="keyword">sig</span></code> <a href="Misc.Error_style.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span id="VALnormalise_eol"><span class="keyword">val</span> normalise_eol</span> : <code class="type">string -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">normalise_eol s</code> returns a fresh copy of <code class="code">s</code> with any '\r' characters
removed. Intended for pre-processing text which will subsequently be printed
on a channel which performs EOL transformations (i.e. Windows)</p>
</div>
</div>
<pre><span id="VALdelete_eol_spaces"><span class="keyword">val</span> delete_eol_spaces</span> : <code class="type">string -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">delete_eol_spaces s</code> returns a fresh copy of <code class="code">s</code> with any end of
line spaces removed. Intended to normalize the output of the
toplevel for tests.</p>
</div>
</div>
<pre><span id="VALpp_two_columns"><span class="keyword">val</span> pp_two_columns</span> : <code class="type">?sep:string -><br> ?max_lines:int -> Format.formatter -> (string * string) list -> unit</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">pp_two_columns ?sep ?max_lines ppf l</code> prints the lines in <code class="code">l</code> as two
columns separated by <code class="code">sep</code> ("|" by default). <code class="code">max_lines</code> can be used to
indicate a maximum number of lines to print -- an ellipsis gets inserted at
the middle if the input has too many lines.</p>
<p>Example:</p>
<pre class="verbatim">pp_two_columns ~max_lines:3 Format.std_formatter [
"abc", "hello";
"def", "zzz";
"a" , "bllbl";
"bb" , "dddddd";
]</pre>
<p>prints</p>
<pre class="verbatim"> abc | hello
...
bb | dddddd
</pre></div>
</div>
<pre><span id="VALshow_config_and_exit"><span class="keyword">val</span> show_config_and_exit</span> : <code class="type">unit -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>configuration variables</p>
</div>
</div>
<pre><span id="VALshow_config_variable_and_exit"><span class="keyword">val</span> show_config_variable_and_exit</span> : <code class="type">string -> unit</code></pre>
<pre><span id="VALget_build_path_prefix_map"><span class="keyword">val</span> get_build_path_prefix_map</span> : <code class="type">unit -> <a href="Build_path_prefix_map.html#TYPEmap">Build_path_prefix_map.map</a> option</code></pre><div class="info ">
<div class="info-desc">
<p>Returns the map encoded in the <code class="code"><span class="constructor">BUILD_PATH_PREFIX_MAP</span></code> environment
variable.</p>
</div>
</div>
<pre><span id="VALdebug_prefix_map_flags"><span class="keyword">val</span> debug_prefix_map_flags</span> : <code class="type">unit -> string list</code></pre><div class="info ">
<div class="info-desc">
<p>Returns the list of <code class="code">--debug-prefix-map</code> flags to be passed to the
assembler, built from the <code class="code"><span class="constructor">BUILD_PATH_PREFIX_MAP</span></code> environment variable.</p>
</div>
</div>
<pre><span id="VALprint_if"><span class="keyword">val</span> print_if</span> : <code class="type">Format.formatter -><br> bool ref -> (Format.formatter -> 'a -> unit) -> 'a -> 'a</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">print_if ppf flag fmt x</code> prints <code class="code">x</code> with <code class="code">fmt</code> on <code class="code">ppf</code> if <code class="code">b</code> is true.</p>
</div>
</div>
<pre><span id="TYPEfilepath"><span class="keyword">type</span> <code class="type"></code>filepath</span> = <code class="type">string</code> </pre>
<pre><span id="TYPEmodname"><span class="keyword">type</span> <code class="type"></code>modname</span> = <code class="type">string</code> </pre>
<pre><span id="TYPEcrcs"><span class="keyword">type</span> <code class="type"></code>crcs</span> = <code class="type">(<a href="Misc.html#TYPEmodname">modname</a> * Digest.t option) list</code> </pre>
<pre><span id="TYPEalerts"><span class="keyword">type</span> <code class="type"></code>alerts</span> = <code class="type">string Stdlib.String.Map.t</code> </pre>
<pre><span id="MODULEEnvLazy"><span class="keyword">module</span> <a href="Misc.EnvLazy.html">EnvLazy</a></span>: <code class="code"><span class="keyword">sig</span></code> <a href="Misc.EnvLazy.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span id="MODULEMagic_number"><span class="keyword">module</span> <a href="Misc.Magic_number.html">Magic_number</a></span>: <code class="code"><span class="keyword">sig</span></code> <a href="Misc.Magic_number.html">..</a> <code class="code"><span class="keyword">end</span></code></pre></body></html>
|