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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="Start" href="index.html">
<link rel="previous" href="Lexing.html">
<link rel="next" href="ListLabels.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" rel="Chapter" href="Arg.html">
<link title="Arith_status" rel="Chapter" href="Arith_status.html">
<link title="Array" rel="Chapter" href="Array.html">
<link title="ArrayLabels" rel="Chapter" href="ArrayLabels.html">
<link title="Big_int" rel="Chapter" href="Big_int.html">
<link title="Bigarray" rel="Chapter" href="Bigarray.html">
<link title="Buffer" rel="Chapter" href="Buffer.html">
<link title="Callback" rel="Chapter" href="Callback.html">
<link title="CamlinternalMod" rel="Chapter" href="CamlinternalMod.html">
<link title="CamlinternalOO" rel="Chapter" href="CamlinternalOO.html">
<link title="Char" rel="Chapter" href="Char.html">
<link title="Complex" rel="Chapter" href="Complex.html">
<link title="Condition" rel="Chapter" href="Condition.html">
<link title="Dbm" rel="Chapter" href="Dbm.html">
<link title="Digest" rel="Chapter" href="Digest.html">
<link title="Dynlink" rel="Chapter" href="Dynlink.html">
<link title="Event" rel="Chapter" href="Event.html">
<link title="Filename" rel="Chapter" href="Filename.html">
<link title="Format" rel="Chapter" href="Format.html">
<link title="Gc" rel="Chapter" href="Gc.html">
<link title="Genlex" rel="Chapter" href="Genlex.html">
<link title="Graphics" rel="Chapter" href="Graphics.html">
<link title="GraphicsX11" rel="Chapter" href="GraphicsX11.html">
<link title="Hashtbl" rel="Chapter" href="Hashtbl.html">
<link title="Int32" rel="Chapter" href="Int32.html">
<link title="Int64" rel="Chapter" href="Int64.html">
<link title="Lazy" rel="Chapter" href="Lazy.html">
<link title="Lexing" rel="Chapter" href="Lexing.html">
<link title="List" rel="Chapter" href="List.html">
<link title="ListLabels" rel="Chapter" href="ListLabels.html">
<link title="Map" rel="Chapter" href="Map.html">
<link title="Marshal" rel="Chapter" href="Marshal.html">
<link title="MoreLabels" rel="Chapter" href="MoreLabels.html">
<link title="Mutex" rel="Chapter" href="Mutex.html">
<link title="Nativeint" rel="Chapter" href="Nativeint.html">
<link title="Num" rel="Chapter" href="Num.html">
<link title="Obj" rel="Chapter" href="Obj.html">
<link title="Oo" rel="Chapter" href="Oo.html">
<link title="Parsing" rel="Chapter" href="Parsing.html">
<link title="Pervasives" rel="Chapter" href="Pervasives.html">
<link title="Printexc" rel="Chapter" href="Printexc.html">
<link title="Printf" rel="Chapter" href="Printf.html">
<link title="Queue" rel="Chapter" href="Queue.html">
<link title="Random" rel="Chapter" href="Random.html">
<link title="Scanf" rel="Chapter" href="Scanf.html">
<link title="Set" rel="Chapter" href="Set.html">
<link title="Sort" rel="Chapter" href="Sort.html">
<link title="Stack" rel="Chapter" href="Stack.html">
<link title="StdLabels" rel="Chapter" href="StdLabels.html">
<link title="Str" rel="Chapter" href="Str.html">
<link title="Stream" rel="Chapter" href="Stream.html">
<link title="String" rel="Chapter" href="String.html">
<link title="StringLabels" rel="Chapter" href="StringLabels.html">
<link title="Sys" rel="Chapter" href="Sys.html">
<link title="Thread" rel="Chapter" href="Thread.html">
<link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html">
<link title="Unix" rel="Chapter" href="Unix.html">
<link title="UnixLabels" rel="Chapter" href="UnixLabels.html">
<link title="Weak" rel="Chapter" href="Weak.html"><link title="Iterators" rel="Section" href="#6_Iterators">
<link title="Iterators on two lists" rel="Section" href="#6_Iteratorsontwolists">
<link title="List scanning" rel="Section" href="#6_Listscanning">
<link title="List searching" rel="Section" href="#6_Listsearching">
<link title="Association lists" rel="Section" href="#6_Associationlists">
<link title="Lists of pairs" rel="Section" href="#6_Listsofpairs">
<link title="Sorting" rel="Section" href="#6_Sorting">
<title>List</title>
</head>
<body>
<div class="navbar"><a href="Lexing.html">Previous</a>
<a href="index.html">Up</a>
<a href="ListLabels.html">Next</a>
</div>
<center><h1>Module <a href="type_List.html">List</a></h1></center>
<br>
<pre><span class="keyword">module</span> List: <code class="code"><span class="keyword">sig</span></code> <a href="List.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>List operations.
<p>
Some functions are flagged as not tail-recursive. A tail-recursive
function uses constant stack space, while a non-tail-recursive function
uses stack space proportional to the length of its list argument, which
can be a problem with very long lists. When the function takes several
list arguments, an approximate formula giving stack usage (in some
unspecified constant unit) is shown in parentheses.
<p>
The above considerations can usually be ignored if your lists are not
longer than about 10000 elements.<br>
<hr width="100%">
<pre><span class="keyword">val</span> <a name="VALlength"></a>length : <code class="type">'a list -> int</code></pre><div class="info">
Return the length (number of elements) of the given list.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALhd"></a>hd : <code class="type">'a list -> 'a</code></pre><div class="info">
Return the first element of the given list. Raise
<code class="code"><span class="constructor">Failure</span> <span class="string">"hd"</span></code> if the list is empty.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALtl"></a>tl : <code class="type">'a list -> 'a list</code></pre><div class="info">
Return the given list without its first element. Raise
<code class="code"><span class="constructor">Failure</span> <span class="string">"tl"</span></code> if the list is empty.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALnth"></a>nth : <code class="type">'a list -> int -> 'a</code></pre><div class="info">
Return the n-th element of the given list.
The first element (head of the list) is at position 0.
Raise <code class="code"><span class="constructor">Failure</span> <span class="string">"nth"</span></code> if the list is too short.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALrev"></a>rev : <code class="type">'a list -> 'a list</code></pre><div class="info">
List reversal.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALappend"></a>append : <code class="type">'a list -> 'a list -> 'a list</code></pre><div class="info">
Catenate two lists. Same function as the infix operator <code class="code">@</code>.
Not tail-recursive (length of the first argument). The <code class="code">@</code>
operator is not tail-recursive either.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALrev_append"></a>rev_append : <code class="type">'a list -> 'a list -> 'a list</code></pre><div class="info">
<code class="code"><span class="constructor">List</span>.rev_append l1 l2</code> reverses <code class="code">l1</code> and concatenates it to <code class="code">l2</code>.
This is equivalent to <a href="List.html#VALrev"><code class="code"><span class="constructor">List</span>.rev</code></a><code class="code"> l1 @ l2</code>, but <code class="code">rev_append</code> is
tail-recursive and more efficient.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALconcat"></a>concat : <code class="type">'a list list -> 'a list</code></pre><div class="info">
Concatenate a list of lists. The elements of the argument are all
concatenated together (in the same order) to give the result.
Not tail-recursive
(length of the argument + length of the longest sub-list).<br>
</div>
<pre><span class="keyword">val</span> <a name="VALflatten"></a>flatten : <code class="type">'a list list -> 'a list</code></pre><div class="info">
Same as <code class="code">concat</code>. Not tail-recursive
(length of the argument + length of the longest sub-list).<br>
</div>
<br>
<a name="6_Iterators"></a>
<h6>Iterators</h6><br>
<pre><span class="keyword">val</span> <a name="VALiter"></a>iter : <code class="type">('a -> unit) -> 'a list -> unit</code></pre><div class="info">
<code class="code"><span class="constructor">List</span>.iter f [a1; ...; an]</code> applies function <code class="code">f</code> in turn to
<code class="code">a1; ...; an</code>. It is equivalent to
<code class="code"><span class="keyword">begin</span> f a1; f a2; ...; f an; () <span class="keyword">end</span></code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALmap"></a>map : <code class="type">('a -> 'b) -> 'a list -> 'b list</code></pre><div class="info">
<code class="code"><span class="constructor">List</span>.map f [a1; ...; an]</code> applies function <code class="code">f</code> to <code class="code">a1, ..., an</code>,
and builds the list <code class="code">[f a1; ...; f an]</code>
with the results returned by <code class="code">f</code>. Not tail-recursive.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALrev_map"></a>rev_map : <code class="type">('a -> 'b) -> 'a list -> 'b list</code></pre><div class="info">
<code class="code"><span class="constructor">List</span>.rev_map f l</code> gives the same result as
<a href="List.html#VALrev"><code class="code"><span class="constructor">List</span>.rev</code></a><code class="code"> (</code><a href="List.html#VALmap"><code class="code"><span class="constructor">List</span>.map</code></a><code class="code"> f l)</code>, but is tail-recursive and
more efficient.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfold_left"></a>fold_left : <code class="type">('a -> 'b -> 'a) -> 'a -> 'b list -> 'a</code></pre><div class="info">
<code class="code"><span class="constructor">List</span>.fold_left f a [b1; ...; bn]</code> is
<code class="code">f (... (f (f a b1) b2) ...) bn</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfold_right"></a>fold_right : <code class="type">('a -> 'b -> 'b) -> 'a list -> 'b -> 'b</code></pre><div class="info">
<code class="code"><span class="constructor">List</span>.fold_right f [a1; ...; an] b</code> is
<code class="code">f a1 (f a2 (... (f an b) ...))</code>. Not tail-recursive.<br>
</div>
<br>
<a name="6_Iteratorsontwolists"></a>
<h6>Iterators on two lists</h6><br>
<pre><span class="keyword">val</span> <a name="VALiter2"></a>iter2 : <code class="type">('a -> 'b -> unit) -> 'a list -> 'b list -> unit</code></pre><div class="info">
<code class="code"><span class="constructor">List</span>.iter2 f [a1; ...; an] [b1; ...; bn]</code> calls in turn
<code class="code">f a1 b1; ...; f an bn</code>.
Raise <code class="code"><span class="constructor">Invalid_argument</span></code> if the two lists have
different lengths.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALmap2"></a>map2 : <code class="type">('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list</code></pre><div class="info">
<code class="code"><span class="constructor">List</span>.map2 f [a1; ...; an] [b1; ...; bn]</code> is
<code class="code">[f a1 b1; ...; f an bn]</code>.
Raise <code class="code"><span class="constructor">Invalid_argument</span></code> if the two lists have
different lengths. Not tail-recursive.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALrev_map2"></a>rev_map2 : <code class="type">('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list</code></pre><div class="info">
<code class="code"><span class="constructor">List</span>.rev_map2 f l1 l2</code> gives the same result as
<a href="List.html#VALrev"><code class="code"><span class="constructor">List</span>.rev</code></a><code class="code"> (</code><a href="List.html#VALmap2"><code class="code"><span class="constructor">List</span>.map2</code></a><code class="code"> f l1 l2)</code>, but is tail-recursive and
more efficient.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfold_left2"></a>fold_left2 : <code class="type">('a -> 'b -> 'c -> 'a) -> 'a -> 'b list -> 'c list -> 'a</code></pre><div class="info">
<code class="code"><span class="constructor">List</span>.fold_left2 f a [b1; ...; bn] [c1; ...; cn]</code> is
<code class="code">f (... (f (f a b1 c1) b2 c2) ...) bn cn</code>.
Raise <code class="code"><span class="constructor">Invalid_argument</span></code> if the two lists have
different lengths.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfold_right2"></a>fold_right2 : <code class="type">('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c</code></pre><div class="info">
<code class="code"><span class="constructor">List</span>.fold_right2 f [a1; ...; an] [b1; ...; bn] c</code> is
<code class="code">f a1 b1 (f a2 b2 (... (f an bn c) ...))</code>.
Raise <code class="code"><span class="constructor">Invalid_argument</span></code> if the two lists have
different lengths. Not tail-recursive.<br>
</div>
<br>
<a name="6_Listscanning"></a>
<h6>List scanning</h6><br>
<pre><span class="keyword">val</span> <a name="VALfor_all"></a>for_all : <code class="type">('a -> bool) -> 'a list -> bool</code></pre><div class="info">
<code class="code">for_all p [a1; ...; an]</code> checks if all elements of the list
satisfy the predicate <code class="code">p</code>. That is, it returns
<code class="code">(p a1) <span class="keywordsign">&&</span> (p a2) <span class="keywordsign">&&</span> ... <span class="keywordsign">&&</span> (p an)</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALexists"></a>exists : <code class="type">('a -> bool) -> 'a list -> bool</code></pre><div class="info">
<code class="code">exists p [a1; ...; an]</code> checks if at least one element of
the list satisfies the predicate <code class="code">p</code>. That is, it returns
<code class="code">(p a1) <span class="keywordsign">||</span> (p a2) <span class="keywordsign">||</span> ... <span class="keywordsign">||</span> (p an)</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfor_all2"></a>for_all2 : <code class="type">('a -> 'b -> bool) -> 'a list -> 'b list -> bool</code></pre><div class="info">
Same as <a href="List.html#VALfor_all"><code class="code"><span class="constructor">List</span>.for_all</code></a>, but for a two-argument predicate.
Raise <code class="code"><span class="constructor">Invalid_argument</span></code> if the two lists have
different lengths.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALexists2"></a>exists2 : <code class="type">('a -> 'b -> bool) -> 'a list -> 'b list -> bool</code></pre><div class="info">
Same as <a href="List.html#VALexists"><code class="code"><span class="constructor">List</span>.exists</code></a>, but for a two-argument predicate.
Raise <code class="code"><span class="constructor">Invalid_argument</span></code> if the two lists have
different lengths.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALmem"></a>mem : <code class="type">'a -> 'a list -> bool</code></pre><div class="info">
<code class="code">mem a l</code> is true if and only if <code class="code">a</code> is equal
to an element of <code class="code">l</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALmemq"></a>memq : <code class="type">'a -> 'a list -> bool</code></pre><div class="info">
Same as <a href="List.html#VALmem"><code class="code"><span class="constructor">List</span>.mem</code></a>, but uses physical equality instead of structural
equality to compare list elements.<br>
</div>
<br>
<a name="6_Listsearching"></a>
<h6>List searching</h6><br>
<pre><span class="keyword">val</span> <a name="VALfind"></a>find : <code class="type">('a -> bool) -> 'a list -> 'a</code></pre><div class="info">
<code class="code">find p l</code> returns the first element of the list <code class="code">l</code>
that satisfies the predicate <code class="code">p</code>.
Raise <code class="code"><span class="constructor">Not_found</span></code> if there is no value that satisfies <code class="code">p</code> in the
list <code class="code">l</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfilter"></a>filter : <code class="type">('a -> bool) -> 'a list -> 'a list</code></pre><div class="info">
<code class="code">filter p l</code> returns all the elements of the list <code class="code">l</code>
that satisfy the predicate <code class="code">p</code>. The order of the elements
in the input list is preserved.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfind_all"></a>find_all : <code class="type">('a -> bool) -> 'a list -> 'a list</code></pre><div class="info">
<code class="code">find_all</code> is another name for <a href="List.html#VALfilter"><code class="code"><span class="constructor">List</span>.filter</code></a>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALpartition"></a>partition : <code class="type">('a -> bool) -> 'a list -> 'a list * 'a list</code></pre><div class="info">
<code class="code">partition p l</code> returns a pair of lists <code class="code">(l1, l2)</code>, where
<code class="code">l1</code> is the list of all the elements of <code class="code">l</code> that
satisfy the predicate <code class="code">p</code>, and <code class="code">l2</code> is the list of all the
elements of <code class="code">l</code> that do not satisfy <code class="code">p</code>.
The order of the elements in the input list is preserved.<br>
</div>
<br>
<a name="6_Associationlists"></a>
<h6>Association lists</h6><br>
<pre><span class="keyword">val</span> <a name="VALassoc"></a>assoc : <code class="type">'a -> ('a * 'b) list -> 'b</code></pre><div class="info">
<code class="code">assoc a l</code> returns the value associated with key <code class="code">a</code> in the list of
pairs <code class="code">l</code>. That is,
<code class="code">assoc a [ ...; (a,b); ...] = b</code>
if <code class="code">(a,b)</code> is the leftmost binding of <code class="code">a</code> in list <code class="code">l</code>.
Raise <code class="code"><span class="constructor">Not_found</span></code> if there is no value associated with <code class="code">a</code> in the
list <code class="code">l</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALassq"></a>assq : <code class="type">'a -> ('a * 'b) list -> 'b</code></pre><div class="info">
Same as <a href="List.html#VALassoc"><code class="code"><span class="constructor">List</span>.assoc</code></a>, but uses physical equality instead of structural
equality to compare keys.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALmem_assoc"></a>mem_assoc : <code class="type">'a -> ('a * 'b) list -> bool</code></pre><div class="info">
Same as <a href="List.html#VALassoc"><code class="code"><span class="constructor">List</span>.assoc</code></a>, but simply return true if a binding exists,
and false if no bindings exist for the given key.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALmem_assq"></a>mem_assq : <code class="type">'a -> ('a * 'b) list -> bool</code></pre><div class="info">
Same as <a href="List.html#VALmem_assoc"><code class="code"><span class="constructor">List</span>.mem_assoc</code></a>, but uses physical equality instead of
structural equality to compare keys.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALremove_assoc"></a>remove_assoc : <code class="type">'a -> ('a * 'b) list -> ('a * 'b) list</code></pre><div class="info">
<code class="code">remove_assoc a l</code> returns the list of
pairs <code class="code">l</code> without the first pair with key <code class="code">a</code>, if any.
Not tail-recursive.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALremove_assq"></a>remove_assq : <code class="type">'a -> ('a * 'b) list -> ('a * 'b) list</code></pre><div class="info">
Same as <a href="List.html#VALremove_assoc"><code class="code"><span class="constructor">List</span>.remove_assoc</code></a>, but uses physical equality instead
of structural equality to compare keys. Not tail-recursive.<br>
</div>
<br>
<a name="6_Listsofpairs"></a>
<h6>Lists of pairs</h6><br>
<pre><span class="keyword">val</span> <a name="VALsplit"></a>split : <code class="type">('a * 'b) list -> 'a list * 'b list</code></pre><div class="info">
Transform a list of pairs into a pair of lists:
<code class="code">split [(a1,b1); ...; (an,bn)]</code> is <code class="code">([a1; ...; an], [b1; ...; bn])</code>.
Not tail-recursive.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALcombine"></a>combine : <code class="type">'a list -> 'b list -> ('a * 'b) list</code></pre><div class="info">
Transform a pair of lists into a list of pairs:
<code class="code">combine [a1; ...; an] [b1; ...; bn]</code> is
<code class="code">[(a1,b1); ...; (an,bn)]</code>.
Raise <code class="code"><span class="constructor">Invalid_argument</span></code> if the two lists
have different lengths. Not tail-recursive.<br>
</div>
<br>
<a name="6_Sorting"></a>
<h6>Sorting</h6><br>
<pre><span class="keyword">val</span> <a name="VALsort"></a>sort : <code class="type">('a -> 'a -> int) -> 'a list -> 'a list</code></pre><div class="info">
Sort a list in increasing order according to a comparison
function. The comparison function must return 0 if its arguments
compare as equal, a positive integer if the first is greater,
and a negative integer if the first is smaller (see Array.sort for
a complete specification). For example,
<a href="Pervasives.html#VALcompare"><code class="code">compare</code></a> is a suitable comparison function.
The resulting list is sorted in increasing order.
<code class="code"><span class="constructor">List</span>.sort</code> is guaranteed to run in constant heap space
(in addition to the size of the result list) and logarithmic
stack space.
<p>
The current implementation uses Merge Sort. It runs in constant
heap space and logarithmic stack space.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALstable_sort"></a>stable_sort : <code class="type">('a -> 'a -> int) -> 'a list -> 'a list</code></pre><div class="info">
Same as <a href="List.html#VALsort"><code class="code"><span class="constructor">List</span>.sort</code></a>, but the sorting algorithm is guaranteed to
be stable (i.e. elements that compare equal are kept in their
original order) .
<p>
The current implementation uses Merge Sort. It runs in constant
heap space and logarithmic stack space.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfast_sort"></a>fast_sort : <code class="type">('a -> 'a -> int) -> 'a list -> 'a list</code></pre><div class="info">
Same as <a href="List.html#VALsort"><code class="code"><span class="constructor">List</span>.sort</code></a> or <a href="List.html#VALstable_sort"><code class="code"><span class="constructor">List</span>.stable_sort</code></a>, whichever is faster
on typical input.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALmerge"></a>merge : <code class="type">('a -> 'a -> int) -> 'a list -> 'a list -> 'a list</code></pre><div class="info">
Merge two lists:
Assuming that <code class="code">l1</code> and <code class="code">l2</code> are sorted according to the
comparison function <code class="code">cmp</code>, <code class="code">merge cmp l1 l2</code> will return a
sorted list containting all the elements of <code class="code">l1</code> and <code class="code">l2</code>.
If several elements compare equal, the elements of <code class="code">l1</code> will be
before the elements of <code class="code">l2</code>.
Not tail-recursive (sum of the lengths of the arguments).<br>
</div>
</body></html>
|