ocaml-containers/0.17/CCFun.html
2016-04-22 23:45:40 +02:00

189 lines
No EOL
12 KiB
HTML

<!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=utf-8" http-equiv="Content-Type">
<link rel="Start" href="index.html">
<link rel="previous" href="CCPair.html">
<link rel="next" href="CCHash.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 methods" rel=Appendix href="index_methods.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="CCVector" rel="Chapter" href="CCVector.html">
<link title="CCPrint" rel="Chapter" href="CCPrint.html">
<link title="CCError" rel="Chapter" href="CCError.html">
<link title="CCHeap" rel="Chapter" href="CCHeap.html">
<link title="CCList" rel="Chapter" href="CCList.html">
<link title="CCOpt" rel="Chapter" href="CCOpt.html">
<link title="CCPair" rel="Chapter" href="CCPair.html">
<link title="CCFun" rel="Chapter" href="CCFun.html">
<link title="CCHash" rel="Chapter" href="CCHash.html">
<link title="CCInt" rel="Chapter" href="CCInt.html">
<link title="CCBool" rel="Chapter" href="CCBool.html">
<link title="CCFloat" rel="Chapter" href="CCFloat.html">
<link title="CCArray" rel="Chapter" href="CCArray.html">
<link title="CCRef" rel="Chapter" href="CCRef.html">
<link title="CCSet" rel="Chapter" href="CCSet.html">
<link title="CCOrd" rel="Chapter" href="CCOrd.html">
<link title="CCRandom" rel="Chapter" href="CCRandom.html">
<link title="CCString" rel="Chapter" href="CCString.html">
<link title="CCHashtbl" rel="Chapter" href="CCHashtbl.html">
<link title="CCMap" rel="Chapter" href="CCMap.html">
<link title="CCFormat" rel="Chapter" href="CCFormat.html">
<link title="CCIO" rel="Chapter" href="CCIO.html">
<link title="CCInt64" rel="Chapter" href="CCInt64.html">
<link title="CCChar" rel="Chapter" href="CCChar.html">
<link title="CCResult" rel="Chapter" href="CCResult.html">
<link title="Containers" rel="Chapter" href="Containers.html">
<link title="CCKTree" rel="Chapter" href="CCKTree.html">
<link title="CCKList" rel="Chapter" href="CCKList.html">
<link title="CCLazy_list" rel="Chapter" href="CCLazy_list.html">
<link title="CCMultiMap" rel="Chapter" href="CCMultiMap.html">
<link title="CCMultiSet" rel="Chapter" href="CCMultiSet.html">
<link title="CCTrie" rel="Chapter" href="CCTrie.html">
<link title="CCFlatHashtbl" rel="Chapter" href="CCFlatHashtbl.html">
<link title="CCCache" rel="Chapter" href="CCCache.html">
<link title="CCPersistentHashtbl" rel="Chapter" href="CCPersistentHashtbl.html">
<link title="CCDeque" rel="Chapter" href="CCDeque.html">
<link title="CCFQueue" rel="Chapter" href="CCFQueue.html">
<link title="CCBV" rel="Chapter" href="CCBV.html">
<link title="CCMixtbl" rel="Chapter" href="CCMixtbl.html">
<link title="CCMixmap" rel="Chapter" href="CCMixmap.html">
<link title="CCRingBuffer" rel="Chapter" href="CCRingBuffer.html">
<link title="CCIntMap" rel="Chapter" href="CCIntMap.html">
<link title="CCPersistentArray" rel="Chapter" href="CCPersistentArray.html">
<link title="CCMixset" rel="Chapter" href="CCMixset.html">
<link title="CCHashconsedSet" rel="Chapter" href="CCHashconsedSet.html">
<link title="CCGraph" rel="Chapter" href="CCGraph.html">
<link title="CCHashSet" rel="Chapter" href="CCHashSet.html">
<link title="CCBitField" rel="Chapter" href="CCBitField.html">
<link title="CCHashTrie" rel="Chapter" href="CCHashTrie.html">
<link title="CCBloom" rel="Chapter" href="CCBloom.html">
<link title="CCWBTree" rel="Chapter" href="CCWBTree.html">
<link title="CCRAL" rel="Chapter" href="CCRAL.html">
<link title="CCAllocCache" rel="Chapter" href="CCAllocCache.html">
<link title="CCImmutArray" rel="Chapter" href="CCImmutArray.html">
<link title="CCHet" rel="Chapter" href="CCHet.html">
<link title="Containers_string" rel="Chapter" href="Containers_string.html">
<link title="CCKMP" rel="Chapter" href="CCKMP.html">
<link title="CCLevenshtein" rel="Chapter" href="CCLevenshtein.html">
<link title="CCApp_parse" rel="Chapter" href="CCApp_parse.html">
<link title="CCParse" rel="Chapter" href="CCParse.html">
<link title="CCBigstring" rel="Chapter" href="CCBigstring.html">
<link title="CCArray1" rel="Chapter" href="CCArray1.html">
<link title="CCPool" rel="Chapter" href="CCPool.html">
<link title="CCLock" rel="Chapter" href="CCLock.html">
<link title="CCSemaphore" rel="Chapter" href="CCSemaphore.html">
<link title="CCThread" rel="Chapter" href="CCThread.html">
<link title="CCBlockingQueue" rel="Chapter" href="CCBlockingQueue.html">
<link title="CCTimer" rel="Chapter" href="CCTimer.html">
<link title="Containers_advanced" rel="Chapter" href="Containers_advanced.html">
<link title="CCLinq" rel="Chapter" href="CCLinq.html">
<link title="CCBatch" rel="Chapter" href="CCBatch.html">
<link title="CCCat" rel="Chapter" href="CCCat.html">
<link title="CCMonadIO" rel="Chapter" href="CCMonadIO.html">
<link title="Containers_io_is_deprecated" rel="Chapter" href="Containers_io_is_deprecated.html">
<link title="CCUnix" rel="Chapter" href="CCUnix.html">
<link title="CCSexp" rel="Chapter" href="CCSexp.html">
<link title="CCSexpM" rel="Chapter" href="CCSexpM.html"><link title="Monad" rel="Section" href="#2_Monad">
<title>Containers doc : CCFun</title>
</head>
<body>
<div class="navbar"><a class="pre" href="CCPair.html" title="CCPair">Previous</a>
&nbsp;<a class="up" href="index.html" title="Index">Up</a>
&nbsp;<a class="post" href="CCHash.html" title="CCHash">Next</a>
</div>
<h1>Module <a href="type_CCFun.html">CCFun</a></h1>
<pre><span class="keyword">module</span> CCFun: <code class="code"><span class="keyword">sig</span></code> <a href="CCFun.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
<h1 id="1_BasicFunctions">Basic Functions</h1><br>
</div>
<hr width="100%">
<pre><span id="VAL(|>)"><span class="keyword">val</span> (|&gt;)</span> : <code class="type">'a -> ('a -> 'b) -> 'b</code></pre><div class="info ">
Pipeline. <code class="code">x |&gt; f</code> is the same as <code class="code">f x</code>.<br>
</div>
<pre><span id="VALcompose"><span class="keyword">val</span> compose</span> : <code class="type">('a -> 'b) -> ('b -> 'c) -> 'a -> 'c</code></pre><div class="info ">
Composition<br>
</div>
<pre><span id="VALcompose_binop"><span class="keyword">val</span> compose_binop</span> : <code class="type">('a -> 'b) -> ('b -> 'b -> 'c) -> 'a -> 'a -> 'c</code></pre><div class="info ">
<code class="code">compose_binop f g</code> is <code class="code"><span class="keyword">fun</span> x y <span class="keywordsign">-&gt;</span> g (f x) (f y)</code>
Example (partial order):
<code class="code"><span class="constructor">List</span>.sort (compose_binop fst <span class="constructor">CCInt</span>.compare) [1, <span class="keyword">true</span>; 2, <span class="keyword">false</span>; 1, <span class="keyword">false</span>]</code><br>
<b>Since</b> 0.6<br>
</div>
<pre><span id="VAL(%>)"><span class="keyword">val</span> (%&gt;)</span> : <code class="type">('a -> 'b) -> ('b -> 'c) -> 'a -> 'c</code></pre><div class="info ">
Alias to <code class="code">compose</code><br>
</div>
<pre><span id="VAL(@@)"><span class="keyword">val</span> (@@)</span> : <code class="type">('a -> 'b) -> 'a -> 'b</code></pre><div class="info ">
<code class="code">f @@ x</code> is the same as <code class="code">f x</code>, but right-associative.<br>
<b>Since</b> 0.5<br>
</div>
<pre><span id="VALid"><span class="keyword">val</span> id</span> : <code class="type">'a -> 'a</code></pre><div class="info ">
Identity function<br>
</div>
<pre><span id="VALconst"><span class="keyword">val</span> const</span> : <code class="type">'a -> 'b -> 'a</code></pre><div class="info ">
<code class="code">const x y = x</code> for any <code class="code">y</code><br>
</div>
<pre><span id="VALflip"><span class="keyword">val</span> flip</span> : <code class="type">('a -> 'b -> 'c) -> 'b -> 'a -> 'c</code></pre><div class="info ">
Flip arguments<br>
</div>
<pre><span id="VALcurry"><span class="keyword">val</span> curry</span> : <code class="type">('a * 'b -> 'c) -> 'a -> 'b -> 'c</code></pre>
<pre><span id="VALuncurry"><span class="keyword">val</span> uncurry</span> : <code class="type">('a -> 'b -> 'c) -> 'a * 'b -> 'c</code></pre>
<pre><span id="VALtap"><span class="keyword">val</span> tap</span> : <code class="type">('a -> 'b) -> 'a -> 'a</code></pre><div class="info ">
<code class="code">tap f x</code> evaluates <code class="code">f x</code>, discards it, then returns <code class="code">x</code>. Useful
in a pipeline, for instance:
<pre class="codepre"><code class="code"><span class="constructor">CCArray</span>.(1&nbsp;--&nbsp;10)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&gt;&nbsp;tap&nbsp;<span class="constructor">CCArray</span>.shuffle<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&gt;&nbsp;tap&nbsp;<span class="constructor">CCArray</span>.sort&nbsp;<span class="constructor">Pervasives</span>.compare<br>
&nbsp;&nbsp;&nbsp;&nbsp;</code></pre><br>
</div>
<pre><span id="VAL(%)"><span class="keyword">val</span> (%)</span> : <code class="type">('b -> 'c) -> ('a -> 'b) -> 'a -> 'c</code></pre><div class="info ">
Mathematical composition<br>
</div>
<pre><span id="VALlexicographic"><span class="keyword">val</span> lexicographic</span> : <code class="type">('a -> 'a -> int) -> ('a -> 'a -> int) -> 'a -> 'a -> int</code></pre><div class="info ">
Lexicographic combination of comparison functions<br>
</div>
<pre><span id="VALfinally"><span class="keyword">val</span> finally</span> : <code class="type">h:(unit -> 'b) -> f:(unit -> 'a) -> 'a</code></pre><div class="info ">
<code class="code">finally h f</code> calls <code class="code">f ()</code> and returns its result. If it raises, the
same exception is raised; in <b>any</b> case, <code class="code">h ()</code> is called after
<code class="code">f ()</code> terminates.<br>
</div>
<pre><span id="VALfinally1"><span class="keyword">val</span> finally1</span> : <code class="type">h:(unit -> 'c) -> ('a -> 'b) -> 'a -> 'b</code></pre><div class="info ">
<code class="code">finally1 ~h f x</code> is the same as <code class="code">f x</code>, but after the computation,
<code class="code">h ()</code> is called whether <code class="code">f x</code> rose an exception or not.<br>
<b>Since</b> 0.16<br>
</div>
<pre><span id="VALfinally2"><span class="keyword">val</span> finally2</span> : <code class="type">h:(unit -> 'd) -> ('a -> 'b -> 'c) -> 'a -> 'b -> 'c</code></pre><div class="info ">
<code class="code">finally2 ~h f x y</code> is the same as <code class="code">f x y</code>, but after the computation,
<code class="code">h ()</code> is called whether <code class="code">f x y</code> rose an exception or not.<br>
<b>Since</b> 0.16<br>
</div>
<br>
<h2 id="2_Monad">Monad</h2>
<p>
Functions with a fixed domain are monads in their codomain<br>
<pre><span class="keyword">module</span> <a href="CCFun.Monad.html">Monad</a> <code class="code">(</code><code class="code"><span class="constructor">X</span></code><code class="code"> : </code><code class="code"><span class="keyword">sig</span></code><div class="sig_block">
<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type"></code>t</span> </pre>
</div><code class="code"><span class="keyword">end</span></code><code class="code">) </code>: <code class="code"><span class="keyword">sig</span></code> <a href="CCFun.Monad.html">..</a> <code class="code"><span class="keyword">end</span></code></pre></body></html>