mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
324 lines
No EOL
26 KiB
HTML
324 lines
No EOL
26 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="CCPrint.html">
|
|
<link rel="next" href="CCHeap.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="Basics" rel="Section" href="#2_Basics">
|
|
<link title="Wrappers" rel="Section" href="#2_Wrappers">
|
|
<link title="Applicative" rel="Section" href="#2_Applicative">
|
|
<link title="Infix" rel="Section" href="#2_Infix">
|
|
<link title="Collections" rel="Section" href="#2_Collections">
|
|
<link title="Misc" rel="Section" href="#2_Misc">
|
|
<link title="Conversions" rel="Section" href="#2_Conversions">
|
|
<link title="IO" rel="Section" href="#2_IO">
|
|
<link title="Global Exception Printers" rel="Section" href="#2_GlobalExceptionPrinters">
|
|
<title>Containers doc : CCError</title>
|
|
</head>
|
|
<body>
|
|
<div class="navbar"><a class="pre" href="CCPrint.html" title="CCPrint">Previous</a>
|
|
<a class="up" href="index.html" title="Index">Up</a>
|
|
<a class="post" href="CCHeap.html" title="CCHeap">Next</a>
|
|
</div>
|
|
<h1>Module <a href="type_CCError.html">CCError</a></h1>
|
|
|
|
<pre><span class="keyword">module</span> CCError: <code class="code"><span class="keyword">sig</span></code> <a href="CCError.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
|
|
<h1 id="1_ErrorMonad">Error Monad</h1>
|
|
<p>
|
|
|
|
The variant is polymorphic in the error type<br>
|
|
<b>Since</b> 0.5<br>
|
|
</div>
|
|
<hr width="100%">
|
|
|
|
<pre><span id="TYPEsequence"><span class="keyword">type</span> <code class="type">'a</code> sequence</span> = <code class="type">('a -> unit) -> unit</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEequal"><span class="keyword">type</span> <code class="type">'a</code> equal</span> = <code class="type">'a -> 'a -> bool</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEord"><span class="keyword">type</span> <code class="type">'a</code> ord</span> = <code class="type">'a -> 'a -> int</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEprinter"><span class="keyword">type</span> <code class="type">'a</code> printer</span> = <code class="type">Buffer.t -> 'a -> unit</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEformatter"><span class="keyword">type</span> <code class="type">'a</code> formatter</span> = <code class="type">Format.formatter -> 'a -> unit</code> </pre>
|
|
|
|
<br>
|
|
<h2 id="2_Basics">Basics</h2><br>
|
|
|
|
<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type">('good, 'bad)</code> t</span> = <code class="type">[ `Error of 'bad | `Ok of 'good ]</code> </pre>
|
|
|
|
|
|
<pre><span id="VALreturn"><span class="keyword">val</span> return</span> : <code class="type">'a -> ('a, 'err) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Successfully return a value<br>
|
|
</div>
|
|
|
|
<pre><span id="VALfail"><span class="keyword">val</span> fail</span> : <code class="type">'err -> ('a, 'err) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Fail with an error<br>
|
|
</div>
|
|
|
|
<pre><span id="VALof_exn"><span class="keyword">val</span> of_exn</span> : <code class="type">exn -> ('a, string) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">of_exn e</code> uses <code class="code"><span class="constructor">Printexc</span></code> to print the exception as a string<br>
|
|
</div>
|
|
|
|
<pre><span id="VALof_exn_trace"><span class="keyword">val</span> of_exn_trace</span> : <code class="type">exn -> ('a, string) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">of_exn_trace e</code> is similar to <code class="code">of_exn e</code>, but it adds the stacktrace
|
|
to the error message.
|
|
<p>
|
|
|
|
Remember to call <code class="code"><span class="constructor">Printexc</span>.record_backtrace <span class="keyword">true</span></code> and compile with the
|
|
debug flag for this to work.<br>
|
|
<b>Since</b> 0.14<br>
|
|
</div>
|
|
|
|
<pre><span id="VALfail_printf"><span class="keyword">val</span> fail_printf</span> : <code class="type">('a, Buffer.t, unit, ('a, string) <a href="CCError.html#TYPEt">t</a>) Pervasives.format4 -> 'a</code></pre><div class="info ">
|
|
<code class="code">fail_printf format</code> uses <code class="code">format</code> to obtain an error message
|
|
and then returns <code class="code"><span class="keywordsign">`</span><span class="constructor">Error</span> msg</code><br>
|
|
<b>Since</b> 0.3.3<br>
|
|
</div>
|
|
|
|
<pre><span id="VALmap"><span class="keyword">val</span> map</span> : <code class="type">('a -> 'b) -> ('a, 'err) <a href="CCError.html#TYPEt">t</a> -> ('b, 'err) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Map on success<br>
|
|
</div>
|
|
|
|
<pre><span id="VALmap_err"><span class="keyword">val</span> map_err</span> : <code class="type">('err1 -> 'err2) -> ('a, 'err1) <a href="CCError.html#TYPEt">t</a> -> ('a, 'err2) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Map on error.<br>
|
|
<b>Since</b> 0.5<br>
|
|
</div>
|
|
|
|
<pre><span id="VALmap2"><span class="keyword">val</span> map2</span> : <code class="type">('a -> 'b) -><br> ('err1 -> 'err2) -> ('a, 'err1) <a href="CCError.html#TYPEt">t</a> -> ('b, 'err2) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Same as <a href="CCError.html#VALmap"><code class="code"><span class="constructor">CCError</span>.map</code></a>, but also with a function that can transform
|
|
the error message in case of failure<br>
|
|
</div>
|
|
|
|
<pre><span id="VALiter"><span class="keyword">val</span> iter</span> : <code class="type">('a -> unit) -> ('a, 'b) <a href="CCError.html#TYPEt">t</a> -> unit</code></pre><div class="info ">
|
|
Apply the function only in case of `Ok<br>
|
|
</div>
|
|
|
|
<pre><span id="VALget_exn"><span class="keyword">val</span> get_exn</span> : <code class="type">('a, 'b) <a href="CCError.html#TYPEt">t</a> -> 'a</code></pre><div class="info ">
|
|
Extract the value <code class="code">x</code> from <code class="code"><span class="keywordsign">`</span><span class="constructor">Ok</span> x</code>, fails otherwise.
|
|
You should be careful with this function, and favor other combinators
|
|
whenever possible.<br>
|
|
<b>Raises</b> <code>Invalid_argument</code> if the value is an error.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALcatch"><span class="keyword">val</span> catch</span> : <code class="type">('a, 'err) <a href="CCError.html#TYPEt">t</a> -> ok:('a -> 'b) -> err:('err -> 'b) -> 'b</code></pre><div class="info ">
|
|
<code class="code">catch e ~ok ~err</code> calls either <code class="code">ok</code> or <code class="code">err</code> depending on
|
|
the value of <code class="code">e</code>.
|
|
This is useful for code that does not want to depend on the exact
|
|
definition of <code class="code">(<span class="keywordsign">'</span>a, <span class="keywordsign">'</span>b) t</code> used, for instance once OCaml gets a
|
|
standard <code class="code"><span class="constructor">Result</span>.t</code> type.<br>
|
|
<b>Since</b> 0.12<br>
|
|
</div>
|
|
|
|
<pre><span id="VALflat_map"><span class="keyword">val</span> flat_map</span> : <code class="type">('a -> ('b, 'err) <a href="CCError.html#TYPEt">t</a>) -> ('a, 'err) <a href="CCError.html#TYPEt">t</a> -> ('b, 'err) <a href="CCError.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VAL(>|=)"><span class="keyword">val</span> (>|=)</span> : <code class="type">('a, 'err) <a href="CCError.html#TYPEt">t</a> -> ('a -> 'b) -> ('b, 'err) <a href="CCError.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VAL(>>=)"><span class="keyword">val</span> (>>=)</span> : <code class="type">('a, 'err) <a href="CCError.html#TYPEt">t</a> -> ('a -> ('b, 'err) <a href="CCError.html#TYPEt">t</a>) -> ('b, 'err) <a href="CCError.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALequal"><span class="keyword">val</span> equal</span> : <code class="type">?err:'err <a href="CCError.html#TYPEequal">equal</a> -><br> 'a <a href="CCError.html#TYPEequal">equal</a> -> ('a, 'err) <a href="CCError.html#TYPEt">t</a> <a href="CCError.html#TYPEequal">equal</a></code></pre>
|
|
<pre><span id="VALcompare"><span class="keyword">val</span> compare</span> : <code class="type">?err:'err <a href="CCError.html#TYPEord">ord</a> -> 'a <a href="CCError.html#TYPEord">ord</a> -> ('a, 'err) <a href="CCError.html#TYPEt">t</a> <a href="CCError.html#TYPEord">ord</a></code></pre>
|
|
<pre><span id="VALfold"><span class="keyword">val</span> fold</span> : <code class="type">success:('a -> 'b) -> failure:('err -> 'b) -> ('a, 'err) <a href="CCError.html#TYPEt">t</a> -> 'b</code></pre><div class="info ">
|
|
<code class="code">fold ~success ~failure e</code> opens <code class="code">e</code> and, if <code class="code">e = <span class="keywordsign">`</span><span class="constructor">Ok</span> x</code>, returns
|
|
<code class="code">success x</code>, otherwise <code class="code">e = <span class="keywordsign">`</span><span class="constructor">Error</span> s</code> and it returns <code class="code">failure s</code>.<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_Wrappers">Wrappers</h2>
|
|
<p>
|
|
|
|
The functions <a href="CCError.html#VALguard"><code class="code"><span class="constructor">CCError</span>.guard</code></a>, <a href="CCError.html#VALwrap1"><code class="code"><span class="constructor">CCError</span>.wrap1</code></a>, <a href="CCError.html#VALwrap2"><code class="code"><span class="constructor">CCError</span>.wrap2</code></a> and <a href="CCError.html#VALwrap3"><code class="code"><span class="constructor">CCError</span>.wrap3</code></a> now return
|
|
exceptions in case of failure,<br>
|
|
|
|
<pre><span id="VALguard"><span class="keyword">val</span> guard</span> : <code class="type">(unit -> 'a) -> ('a, exn) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">guard f</code> runs <code class="code">f ()</code> and returns its result wrapped in <code class="code"><span class="keywordsign">`</span><span class="constructor">Ok</span></code>. If
|
|
<code class="code">f ()</code> raises some exception <code class="code">e</code>, then it fails with <code class="code"><span class="keywordsign">`</span><span class="constructor">Error</span> e</code><br>
|
|
</div>
|
|
|
|
<pre><span id="VALguard_str"><span class="keyword">val</span> guard_str</span> : <code class="type">(unit -> 'a) -> ('a, string) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Same as <a href="CCError.html#VALguard"><code class="code"><span class="constructor">CCError</span>.guard</code></a> but uses <a href="CCError.html#VALof_exn"><code class="code"><span class="constructor">CCError</span>.of_exn</code></a> to print the exception.
|
|
See <a href="CCError.html#VALregister_printer"><code class="code"><span class="constructor">CCError</span>.register_printer</code></a><br>
|
|
</div>
|
|
|
|
<pre><span id="VALguard_str_trace"><span class="keyword">val</span> guard_str_trace</span> : <code class="type">(unit -> 'a) -> ('a, string) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Same as <a href="CCError.html#VALguard_str"><code class="code"><span class="constructor">CCError</span>.guard_str</code></a> but uses <a href="CCError.html#VALof_exn_trace"><code class="code"><span class="constructor">CCError</span>.of_exn_trace</code></a> instead of <a href="CCError.html#VALof_exn"><code class="code"><span class="constructor">CCError</span>.of_exn</code></a> so
|
|
that the stack trace is printed.<br>
|
|
<b>Since</b> 0.14<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwrap1"><span class="keyword">val</span> wrap1</span> : <code class="type">('a -> 'b) -> 'a -> ('b, exn) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Same as <a href="CCError.html#VALguard"><code class="code"><span class="constructor">CCError</span>.guard</code></a> but gives the function one argument.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwrap2"><span class="keyword">val</span> wrap2</span> : <code class="type">('a -> 'b -> 'c) -> 'a -> 'b -> ('c, exn) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Same as <a href="CCError.html#VALguard"><code class="code"><span class="constructor">CCError</span>.guard</code></a> but gives the function two arguments.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwrap3"><span class="keyword">val</span> wrap3</span> : <code class="type">('a -> 'b -> 'c -> 'd) -> 'a -> 'b -> 'c -> ('d, exn) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Same as <a href="CCError.html#VALguard"><code class="code"><span class="constructor">CCError</span>.guard</code></a> but gives the function three arguments.<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_Applicative">Applicative</h2><br>
|
|
|
|
<pre><span id="VALpure"><span class="keyword">val</span> pure</span> : <code class="type">'a -> ('a, 'err) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Synonym of <a href="CCError.html#VALreturn"><code class="code"><span class="constructor">CCError</span>.return</code></a><br>
|
|
</div>
|
|
|
|
<pre><span id="VAL(<*>)"><span class="keyword">val</span> (<*>)</span> : <code class="type">('a -> 'b, 'err) <a href="CCError.html#TYPEt">t</a> -> ('a, 'err) <a href="CCError.html#TYPEt">t</a> -> ('b, 'err) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">a <*> b</code> evaluates <code class="code">a</code> and <code class="code">b</code>, and, in case of success, returns
|
|
<code class="code"><span class="keywordsign">`</span><span class="constructor">Ok</span> (a b)</code>. Otherwise, it fails, and the error of <code class="code">a</code> is chosen
|
|
over the error of <code class="code">b</code> if both fail.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALjoin"><span class="keyword">val</span> join</span> : <code class="type">(('a, 'err) <a href="CCError.html#TYPEt">t</a>, 'err) <a href="CCError.html#TYPEt">t</a> -> ('a, 'err) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">join t</code>, in case of success, returns <code class="code"><span class="keywordsign">`</span><span class="constructor">Ok</span> o</code> from <code class="code"><span class="keywordsign">`</span><span class="constructor">Ok</span> (<span class="keywordsign">`</span><span class="constructor">Ok</span> o)</code>. Otherwise,
|
|
it fails with <code class="code"><span class="keywordsign">`</span><span class="constructor">Error</span> e</code> where <code class="code">e</code> is the unwrapped error of <code class="code">t</code>.<br>
|
|
<b>Since</b> 0.15<br>
|
|
</div>
|
|
|
|
<pre><span id="VALboth"><span class="keyword">val</span> both</span> : <code class="type">('a, 'err) <a href="CCError.html#TYPEt">t</a> -> ('b, 'err) <a href="CCError.html#TYPEt">t</a> -> ('a * 'b, 'err) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">both a b</code>, in case of success, returns <code class="code"><span class="keywordsign">`</span><span class="constructor">Ok</span> (o, o')</code> with the ok values
|
|
of <code class="code">a</code> and <code class="code">b</code>. Otherwise, it fails, and the error of <code class="code">a</code> is chosen over the
|
|
error of <code class="code">b</code> if both fail.<br>
|
|
<b>Since</b> 0.15<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_Infix">Infix</h2><br>
|
|
|
|
<pre><span class="keyword">module</span> <a href="CCError.Infix.html">Infix</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCError.Infix.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><br>
|
|
<h2 id="2_Collections">Collections</h2><br>
|
|
|
|
<pre><span id="VALmap_l"><span class="keyword">val</span> map_l</span> : <code class="type">('a -> ('b, 'err) <a href="CCError.html#TYPEt">t</a>) -> 'a list -> ('b list, 'err) <a href="CCError.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALfold_l"><span class="keyword">val</span> fold_l</span> : <code class="type">('b -> 'a -> ('b, 'err) <a href="CCError.html#TYPEt">t</a>) -> 'b -> 'a list -> ('b, 'err) <a href="CCError.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALfold_seq"><span class="keyword">val</span> fold_seq</span> : <code class="type">('b -> 'a -> ('b, 'err) <a href="CCError.html#TYPEt">t</a>) -><br> 'b -> 'a <a href="CCError.html#TYPEsequence">sequence</a> -> ('b, 'err) <a href="CCError.html#TYPEt">t</a></code></pre><br>
|
|
<h2 id="2_Misc">Misc</h2><br>
|
|
|
|
<pre><span id="VALchoose"><span class="keyword">val</span> choose</span> : <code class="type">('a, 'err) <a href="CCError.html#TYPEt">t</a> list -> ('a, 'err list) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">choose l</code> selects a member of <code class="code">l</code> that is a <code class="code"><span class="keywordsign">`</span><span class="constructor">Ok</span> _</code> value,
|
|
or returns <code class="code"><span class="keywordsign">`</span><span class="constructor">Error</span> l</code> otherwise, where <code class="code">l</code> is the list of errors.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALretry"><span class="keyword">val</span> retry</span> : <code class="type">int -> (unit -> ('a, 'err) <a href="CCError.html#TYPEt">t</a>) -> ('a, 'err list) <a href="CCError.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">retry n f</code> calls <code class="code">f</code> at most <code class="code">n</code> times, returning the first result
|
|
of <code class="code">f ()</code> that doesn't fail. If <code class="code">f</code> fails <code class="code">n</code> times, <code class="code">retry n f</code> fails
|
|
with the list of successive errors.<br>
|
|
</div>
|
|
|
|
<pre><span class="keyword">module type</span> <a href="CCError.MONAD.html">MONAD</a> = <code class="code"><span class="keyword">sig</span></code> <a href="CCError.MONAD.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info">
|
|
Monadic Operations
|
|
</div>
|
|
|
|
<pre><span class="keyword">module</span> <a href="CCError.Traverse.html">Traverse</a> <code class="code">(</code><code class="code"><span class="constructor">M</span></code><code class="code"> : </code><code class="type"><a href="CCError.MONAD.html">MONAD</a></code><code class="code">) </code>: <code class="code"><span class="keyword">sig</span></code> <a href="CCError.Traverse.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><br>
|
|
<h2 id="2_Conversions">Conversions</h2><br>
|
|
|
|
<pre><span id="VALto_opt"><span class="keyword">val</span> to_opt</span> : <code class="type">('a, 'b) <a href="CCError.html#TYPEt">t</a> -> 'a option</code></pre>
|
|
<pre><span id="VALof_opt"><span class="keyword">val</span> of_opt</span> : <code class="type">'a option -> ('a, string) <a href="CCError.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALto_seq"><span class="keyword">val</span> to_seq</span> : <code class="type">('a, 'b) <a href="CCError.html#TYPEt">t</a> -> 'a <a href="CCError.html#TYPEsequence">sequence</a></code></pre><br>
|
|
<h2 id="2_IO">IO</h2><br>
|
|
|
|
<pre><span id="VALpp"><span class="keyword">val</span> pp</span> : <code class="type">'a <a href="CCError.html#TYPEprinter">printer</a> -> ('a, string) <a href="CCError.html#TYPEt">t</a> <a href="CCError.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALprint"><span class="keyword">val</span> print</span> : <code class="type">'a <a href="CCError.html#TYPEformatter">formatter</a> -> ('a, string) <a href="CCError.html#TYPEt">t</a> <a href="CCError.html#TYPEformatter">formatter</a></code></pre><br>
|
|
<h2 id="2_GlobalExceptionPrinters">Global Exception Printers</h2>
|
|
<p>
|
|
|
|
One can register exception printers here, so they will be used by <a href="CCError.html#VALguard"><code class="code"><span class="constructor">CCError</span>.guard</code></a>,
|
|
<a href="CCError.html#VALwrap1"><code class="code"><span class="constructor">CCError</span>.wrap1</code></a>, etc. The printers should succeed (print) on exceptions they
|
|
can deal with, and re-raise the exception otherwise. For instance
|
|
if I register a printer for <code class="code"><span class="constructor">Not_found</span></code>, it could look like:
|
|
<p>
|
|
|
|
<pre class="codepre"><code class="code"><span class="constructor">CCError</span>.register_printer<br>
|
|
(<span class="keyword">fun</span> buf exn <span class="keywordsign">-></span> <span class="keyword">match</span> exn <span class="keyword">with</span><br>
|
|
<span class="keywordsign">|</span> <span class="constructor">Not_found</span> <span class="keywordsign">-></span> <span class="constructor">Buffer</span>.add_string buf <span class="string">"Not_found"</span><br>
|
|
<span class="keywordsign">|</span> _ <span class="keywordsign">-></span> raise exn<br>
|
|
);;<br>
|
|
</code></pre>
|
|
This way a printer that doesn't know how to deal with an exception will
|
|
let other printers do it.<br>
|
|
|
|
<pre><span id="VALregister_printer"><span class="keyword">val</span> register_printer</span> : <code class="type">exn <a href="CCError.html#TYPEprinter">printer</a> -> unit</code></pre></body></html> |