<!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="StdLabels.Bytes.html"> <link rel="next" href="StdLabels.String.html"> <link rel="Up" href="StdLabels.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="Arg_helper" rel="Chapter" href="Arg_helper.html"> <link title="Array" rel="Chapter" href="Array.html"> <link title="ArrayLabels" rel="Chapter" href="ArrayLabels.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="Bigarray" rel="Chapter" href="Bigarray.html"> <link title="Buffer" rel="Chapter" href="Buffer.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="Bytes" rel="Chapter" href="Bytes.html"> <link title="BytesLabels" rel="Chapter" href="BytesLabels.html"> <link title="Callback" rel="Chapter" href="Callback.html"> <link title="CamlinternalFormat" rel="Chapter" href="CamlinternalFormat.html"> <link title="CamlinternalFormatBasics" rel="Chapter" href="CamlinternalFormatBasics.html"> <link title="CamlinternalLazy" rel="Chapter" href="CamlinternalLazy.html"> <link title="CamlinternalMod" rel="Chapter" href="CamlinternalMod.html"> <link title="CamlinternalOO" rel="Chapter" href="CamlinternalOO.html"> <link title="Ccomp" rel="Chapter" href="Ccomp.html"> <link title="Char" rel="Chapter" href="Char.html"> <link title="Clflags" rel="Chapter" href="Clflags.html"> <link title="Complex" rel="Chapter" href="Complex.html"> <link title="Condition" rel="Chapter" href="Condition.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="Digest" rel="Chapter" href="Digest.html"> <link title="Docstrings" rel="Chapter" href="Docstrings.html"> <link title="Dynlink" rel="Chapter" href="Dynlink.html"> <link title="Ephemeron" rel="Chapter" href="Ephemeron.html"> <link title="Event" rel="Chapter" href="Event.html"> <link title="Filename" rel="Chapter" href="Filename.html"> <link title="Float" rel="Chapter" href="Float.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="Identifiable" rel="Chapter" href="Identifiable.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="Lexer" rel="Chapter" href="Lexer.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="Location" rel="Chapter" href="Location.html"> <link title="Longident" rel="Chapter" href="Longident.html"> <link title="Map" rel="Chapter" href="Map.html"> <link title="Marshal" rel="Chapter" href="Marshal.html"> <link title="Misc" rel="Chapter" href="Misc.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="Numbers" rel="Chapter" href="Numbers.html"> <link title="Obj" rel="Chapter" href="Obj.html"> <link title="Oo" rel="Chapter" href="Oo.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="Parsing" rel="Chapter" href="Parsing.html"> <link title="Pervasives" rel="Chapter" href="Pervasives.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="Printexc" rel="Chapter" href="Printexc.html"> <link title="Printf" rel="Chapter" href="Printf.html"> <link title="Profile" rel="Chapter" href="Profile.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="Seq" rel="Chapter" href="Seq.html"> <link title="Set" rel="Chapter" href="Set.html"> <link title="Simplif" rel="Chapter" href="Simplif.html"> <link title="Sort" rel="Chapter" href="Sort.html"> <link title="Spacetime" rel="Chapter" href="Spacetime.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="Strongly_connected_components" rel="Chapter" href="Strongly_connected_components.html"> <link title="Syntaxerr" rel="Chapter" href="Syntaxerr.html"> <link title="Sys" rel="Chapter" href="Sys.html"> <link title="Targetint" rel="Chapter" href="Targetint.html"> <link title="Tbl" rel="Chapter" href="Tbl.html"> <link title="Terminfo" rel="Chapter" href="Terminfo.html"> <link title="Thread" rel="Chapter" href="Thread.html"> <link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html"> <link title="Typemod" rel="Chapter" href="Typemod.html"> <link title="Uchar" rel="Chapter" href="Uchar.html"> <link title="Unix" rel="Chapter" href="Unix.html"> <link title="UnixLabels" rel="Chapter" href="UnixLabels.html"> <link title="Warnings" rel="Chapter" href="Warnings.html"> <link title="Weak" rel="Chapter" href="Weak.html"><link title="Iterators" rel="Section" href="#1_Iterators"> <link title="Iterators on two lists" rel="Section" href="#1_Iteratorsontwolists"> <link title="List scanning" rel="Section" href="#1_Listscanning"> <link title="List searching" rel="Section" href="#1_Listsearching"> <link title="Association lists" rel="Section" href="#1_Associationlists"> <link title="Lists of pairs" rel="Section" href="#1_Listsofpairs"> <link title="Sorting" rel="Section" href="#1_Sorting"> <link title="Iterators" rel="Subsection" href="#6_Iterators"> <title>StdLabels.List</title> </head> <body> <div class="navbar"><a class="pre" href="StdLabels.Bytes.html" title="StdLabels.Bytes">Previous</a> <a class="up" href="StdLabels.html" title="StdLabels">Up</a> <a class="post" href="StdLabels.String.html" title="StdLabels.String">Next</a> </div> <h1>Module <a href="type_StdLabels.List.html">StdLabels.List</a></h1> <pre><span id="MODULEList"><span class="keyword">module</span> List</span>: <code class="type"><a href="ListLabels.html">ListLabels</a></code></pre><hr width="100%"> <pre><span id="VALlength"><span class="keyword">val</span> length</span> : <code class="type">'a list -> int</code></pre><div class="info "> <div class="info-desc"> <p>Return the length (number of elements) of the given list.</p> </div> </div> <pre><span id="VALhd"><span class="keyword">val</span> hd</span> : <code class="type">'a list -> 'a</code></pre><div class="info "> <div class="info-desc"> <p>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.</p> </div> </div> <pre><span id="VALcompare_lengths"><span class="keyword">val</span> compare_lengths</span> : <code class="type">'a list -> 'b list -> int</code></pre><div class="info "> <div class="info-desc"> <p>Compare the lengths of two lists. <code class="code">compare_lengths l1 l2</code> is equivalent to <code class="code">compare (length l1) (length l2)</code>, except that the computation stops after itering on the shortest list.</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.05.0</li> </ul> </div> <pre><span id="VALcompare_length_with"><span class="keyword">val</span> compare_length_with</span> : <code class="type">'a list -> len:int -> int</code></pre><div class="info "> <div class="info-desc"> <p>Compare the length of a list to an integer. <code class="code">compare_length_with l n</code> is equivalent to <code class="code">compare (length l) n</code>, except that the computation stops after at most <code class="code">n</code> iterations on the list.</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.05.0</li> </ul> </div> <pre><span id="VALcons"><span class="keyword">val</span> cons</span> : <code class="type">'a -> 'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p><code class="code">cons x xs</code> is <code class="code">x :: xs</code></p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.05.0</li> </ul> </div> <pre><span id="VALtl"><span class="keyword">val</span> tl</span> : <code class="type">'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p>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.</p> </div> </div> <pre><span id="VALnth"><span class="keyword">val</span> nth</span> : <code class="type">'a list -> int -> 'a</code></pre><div class="info "> <div class="info-desc"> <p>Return the <code class="code">n</code>-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. Raise <code class="code"><span class="constructor">Invalid_argument</span> <span class="string">"List.nth"</span></code> if <code class="code">n</code> is negative.</p> </div> </div> <pre><span id="VALnth_opt"><span class="keyword">val</span> nth_opt</span> : <code class="type">'a list -> int -> 'a option</code></pre><div class="info "> <div class="info-desc"> <p>Return the <code class="code">n</code>-th element of the given list. The first element (head of the list) is at position 0. Return <code class="code"><span class="constructor">None</span></code> if the list is too short. Raise <code class="code"><span class="constructor">Invalid_argument</span> <span class="string">"List.nth"</span></code> if <code class="code">n</code> is negative.</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.05</li> </ul> </div> <pre><span id="VALrev"><span class="keyword">val</span> rev</span> : <code class="type">'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p>List reversal.</p> </div> </div> <pre><span id="VALinit"><span class="keyword">val</span> init</span> : <code class="type">len:int -> f:(int -> 'a) -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p><code class="code"><span class="constructor">List</span>.init len f</code> is <code class="code">f 0; f 1; ...; f (len-1)</code>, evaluated left to right.</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.06.0</li> <li><b>Raises</b> <code>Invalid_argument</code> if <code class="code">len < 0</code>.</li> </ul> </div> <pre><span id="VALappend"><span class="keyword">val</span> append</span> : <code class="type">'a list -> 'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p>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.</p> </div> </div> <pre><span id="VALrev_append"><span class="keyword">val</span> rev_append</span> : <code class="type">'a list -> 'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p><code class="code"><span class="constructor">List</span>.rev_append l1 l2</code> reverses <code class="code">l1</code> and concatenates it with <code class="code">l2</code>. This is equivalent to <code class="code">(</code><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.</p> </div> </div> <pre><span id="VALconcat"><span class="keyword">val</span> concat</span> : <code class="type">'a list list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p>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).</p> </div> </div> <pre><span id="VALflatten"><span class="keyword">val</span> flatten</span> : <code class="type">'a list list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p>Same as <code class="code">concat</code>. Not tail-recursive (length of the argument + length of the longest sub-list).</p> </div> </div> <h2 id="1_Iterators">Iterators</h2> <pre><span id="VALiter"><span class="keyword">val</span> iter</span> : <code class="type">f:('a -> unit) -> 'a list -> unit</code></pre><div class="info "> <div class="info-desc"> <p><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>.</p> </div> </div> <pre><span id="VALiteri"><span class="keyword">val</span> iteri</span> : <code class="type">f:(int -> 'a -> unit) -> 'a list -> unit</code></pre><div class="info "> <div class="info-desc"> <p>Same as <a href="List.html#VALiter"><code class="code"><span class="constructor">List</span>.iter</code></a>, but the function is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.00.0</li> </ul> </div> <pre><span id="VALmap"><span class="keyword">val</span> map</span> : <code class="type">f:('a -> 'b) -> 'a list -> 'b list</code></pre><div class="info "> <div class="info-desc"> <p><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.</p> </div> </div> <pre><span id="VALmapi"><span class="keyword">val</span> mapi</span> : <code class="type">f:(int -> 'a -> 'b) -> 'a list -> 'b list</code></pre><div class="info "> <div class="info-desc"> <p>Same as <a href="List.html#VALmap"><code class="code"><span class="constructor">List</span>.map</code></a>, but the function is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.00.0</li> </ul> </div> <pre><span id="VALrev_map"><span class="keyword">val</span> rev_map</span> : <code class="type">f:('a -> 'b) -> 'a list -> 'b list</code></pre><div class="info "> <div class="info-desc"> <p><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.</p> </div> </div> <pre><span id="VALfold_left"><span class="keyword">val</span> fold_left</span> : <code class="type">f:('a -> 'b -> 'a) -> init:'a -> 'b list -> 'a</code></pre><div class="info "> <div class="info-desc"> <p><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>.</p> </div> </div> <pre><span id="VALfold_right"><span class="keyword">val</span> fold_right</span> : <code class="type">f:('a -> 'b -> 'b) -> 'a list -> init:'b -> 'b</code></pre><div class="info "> <div class="info-desc"> <p><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.</p> </div> </div> <h2 id="1_Iteratorsontwolists">Iterators on two lists</h2> <pre><span id="VALiter2"><span class="keyword">val</span> iter2</span> : <code class="type">f:('a -> 'b -> unit) -> 'a list -> 'b list -> unit</code></pre><div class="info "> <div class="info-desc"> <p><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 are determined to have different lengths.</p> </div> </div> <pre><span id="VALmap2"><span class="keyword">val</span> map2</span> : <code class="type">f:('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list</code></pre><div class="info "> <div class="info-desc"> <p><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 are determined to have different lengths. Not tail-recursive.</p> </div> </div> <pre><span id="VALrev_map2"><span class="keyword">val</span> rev_map2</span> : <code class="type">f:('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list</code></pre><div class="info "> <div class="info-desc"> <p><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.</p> </div> </div> <pre><span id="VALfold_left2"><span class="keyword">val</span> fold_left2</span> : <code class="type">f:('a -> 'b -> 'c -> 'a) -> init:'a -> 'b list -> 'c list -> 'a</code></pre><div class="info "> <div class="info-desc"> <p><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 are determined to have different lengths.</p> </div> </div> <pre><span id="VALfold_right2"><span class="keyword">val</span> fold_right2</span> : <code class="type">f:('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> init:'c -> 'c</code></pre><div class="info "> <div class="info-desc"> <p><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 are determined to have different lengths. Not tail-recursive.</p> </div> </div> <h2 id="1_Listscanning">List scanning</h2> <pre><span id="VALfor_all"><span class="keyword">val</span> for_all</span> : <code class="type">f:('a -> bool) -> 'a list -> bool</code></pre><div class="info "> <div class="info-desc"> <p><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>.</p> </div> </div> <pre><span id="VALexists"><span class="keyword">val</span> exists</span> : <code class="type">f:('a -> bool) -> 'a list -> bool</code></pre><div class="info "> <div class="info-desc"> <p><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>.</p> </div> </div> <pre><span id="VALfor_all2"><span class="keyword">val</span> for_all2</span> : <code class="type">f:('a -> 'b -> bool) -> 'a list -> 'b list -> bool</code></pre><div class="info "> <div class="info-desc"> <p>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 are determined to have different lengths.</p> </div> </div> <pre><span id="VALexists2"><span class="keyword">val</span> exists2</span> : <code class="type">f:('a -> 'b -> bool) -> 'a list -> 'b list -> bool</code></pre><div class="info "> <div class="info-desc"> <p>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 are determined to have different lengths.</p> </div> </div> <pre><span id="VALmem"><span class="keyword">val</span> mem</span> : <code class="type">'a -> set:'a list -> bool</code></pre><div class="info "> <div class="info-desc"> <p><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>.</p> </div> </div> <pre><span id="VALmemq"><span class="keyword">val</span> memq</span> : <code class="type">'a -> set:'a list -> bool</code></pre><div class="info "> <div class="info-desc"> <p>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.</p> </div> </div> <h2 id="1_Listsearching">List searching</h2> <pre><span id="VALfind"><span class="keyword">val</span> find</span> : <code class="type">f:('a -> bool) -> 'a list -> 'a</code></pre><div class="info "> <div class="info-desc"> <p><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>.</p> </div> </div> <pre><span id="VALfind_opt"><span class="keyword">val</span> find_opt</span> : <code class="type">f:('a -> bool) -> 'a list -> 'a option</code></pre><div class="info "> <div class="info-desc"> <p><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>. Returns <code class="code"><span class="constructor">None</span></code> if there is no value that satisfies <code class="code">p</code> in the list <code class="code">l</code>.</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.05</li> </ul> </div> <pre><span id="VALfilter"><span class="keyword">val</span> filter</span> : <code class="type">f:('a -> bool) -> 'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p><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.</p> </div> </div> <pre><span id="VALfind_all"><span class="keyword">val</span> find_all</span> : <code class="type">f:('a -> bool) -> 'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p><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>.</p> </div> </div> <pre><span id="VALpartition"><span class="keyword">val</span> partition</span> : <code class="type">f:('a -> bool) -> 'a list -> 'a list * 'a list</code></pre><div class="info "> <div class="info-desc"> <p><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.</p> </div> </div> <h2 id="1_Associationlists">Association lists</h2> <pre><span id="VALassoc"><span class="keyword">val</span> assoc</span> : <code class="type">'a -> ('a * 'b) list -> 'b</code></pre><div class="info "> <div class="info-desc"> <p><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>.</p> </div> </div> <pre><span id="VALassoc_opt"><span class="keyword">val</span> assoc_opt</span> : <code class="type">'a -> ('a * 'b) list -> 'b option</code></pre><div class="info "> <div class="info-desc"> <p><code class="code">assoc_opt 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>. Returns <code class="code"><span class="constructor">None</span></code> if there is no value associated with <code class="code">a</code> in the list <code class="code">l</code>.</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.05</li> </ul> </div> <pre><span id="VALassq"><span class="keyword">val</span> assq</span> : <code class="type">'a -> ('a * 'b) list -> 'b</code></pre><div class="info "> <div class="info-desc"> <p>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.</p> </div> </div> <pre><span id="VALassq_opt"><span class="keyword">val</span> assq_opt</span> : <code class="type">'a -> ('a * 'b) list -> 'b option</code></pre><div class="info "> <div class="info-desc"> <p>Same as <a href="List.html#VALassoc_opt"><code class="code"><span class="constructor">List</span>.assoc_opt</code></a>, but uses physical equality instead of structural equality to compare keys.</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.05.0</li> </ul> </div> <pre><span id="VALmem_assoc"><span class="keyword">val</span> mem_assoc</span> : <code class="type">'a -> map:('a * 'b) list -> bool</code></pre><div class="info "> <div class="info-desc"> <p>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.</p> </div> </div> <pre><span id="VALmem_assq"><span class="keyword">val</span> mem_assq</span> : <code class="type">'a -> map:('a * 'b) list -> bool</code></pre><div class="info "> <div class="info-desc"> <p>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.</p> </div> </div> <pre><span id="VALremove_assoc"><span class="keyword">val</span> remove_assoc</span> : <code class="type">'a -> ('a * 'b) list -> ('a * 'b) list</code></pre><div class="info "> <div class="info-desc"> <p><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.</p> </div> </div> <pre><span id="VALremove_assq"><span class="keyword">val</span> remove_assq</span> : <code class="type">'a -> ('a * 'b) list -> ('a * 'b) list</code></pre><div class="info "> <div class="info-desc"> <p>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.</p> </div> </div> <h2 id="1_Listsofpairs">Lists of pairs</h2> <pre><span id="VALsplit"><span class="keyword">val</span> split</span> : <code class="type">('a * 'b) list -> 'a list * 'b list</code></pre><div class="info "> <div class="info-desc"> <p>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.</p> </div> </div> <pre><span id="VALcombine"><span class="keyword">val</span> combine</span> : <code class="type">'a list -> 'b list -> ('a * 'b) list</code></pre><div class="info "> <div class="info-desc"> <p>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.</p> </div> </div> <h2 id="1_Sorting">Sorting</h2> <pre><span id="VALsort"><span class="keyword">val</span> sort</span> : <code class="type">cmp:('a -> 'a -> int) -> 'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p>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> <p>The current implementation uses Merge Sort. It runs in constant heap space and logarithmic stack space.</p> </div> </div> <pre><span id="VALstable_sort"><span class="keyword">val</span> stable_sort</span> : <code class="type">cmp:('a -> 'a -> int) -> 'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p>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> <p>The current implementation uses Merge Sort. It runs in constant heap space and logarithmic stack space.</p> </div> </div> <pre><span id="VALfast_sort"><span class="keyword">val</span> fast_sort</span> : <code class="type">cmp:('a -> 'a -> int) -> 'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p>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.</p> </div> </div> <pre><span id="VALsort_uniq"><span class="keyword">val</span> sort_uniq</span> : <code class="type">cmp:('a -> 'a -> int) -> 'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p>Same as <a href="List.html#VALsort"><code class="code"><span class="constructor">List</span>.sort</code></a>, but also remove duplicates.</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.03.0</li> </ul> </div> <pre><span id="VALmerge"><span class="keyword">val</span> merge</span> : <code class="type">cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p>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 containing 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).</p> </div> </div> <h7 id="6_Iterators">Iterators</h7> <pre><span id="VALto_seq"><span class="keyword">val</span> to_seq</span> : <code class="type">'a list -> 'a <a href="Seq.html#TYPEt">Seq.t</a></code></pre><div class="info "> <div class="info-desc"> <p>Iterate on the list</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.07</li> </ul> </div> <pre><span id="VALof_seq"><span class="keyword">val</span> of_seq</span> : <code class="type">'a <a href="Seq.html#TYPEt">Seq.t</a> -> 'a list</code></pre><div class="info "> <div class="info-desc"> <p>Create a list from the iterator</p> </div> <ul class="info-attributes"> <li><b>Since</b> 4.07</li> </ul> </div> </body></html>