ocaml-containers/2.3/containers/CCMixmap/index.html
2018-08-06 11:54:50 -05:00

25 lines
No EOL
3.7 KiB
HTML

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>CCMixmap (containers.CCMixmap)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><meta name="generator" content="doc-ock-html v1.0.0-1-g1fc9bf0"/></head><body><nav id="top"><a href="../index.html">Up</a> &mdash; <span class="package">package <a href="../index.html">containers</a></span></nav><header><h1><span class="keyword">Module</span> <span class="module-path">CCMixmap</span></h1></header><h2>Maps with Heterogeneous Values</h2><p><b>status: experimental</b></p><pre><code class="code"> module M = CCMixmap.Make(CCInt)
let inj_int = CCMixmap.create_inj()
let inj_str = CCMixmap.create_inj()
let inj_list_int = CCMixmap.create_inj()
let m =
M.empty
|&gt; M.add ~inj:inj_int 1 1
|&gt; M.add ~inj:inj_str 2 &quot;2&quot;
|&gt; M.add ~inj:inj_list_int 3 [3;3;3]
assert (M.get ~inj:inj_int 1 m = Some 1)
assert (M.get ~inj:inj_str 1 m = None)
assert (M.get ~inj:inj_str 2 m = Some &quot;2&quot;)
assert (M.get ~inj:inj_int 2 m = None)
assert (M.get ~inj:inj_list_int 3 m = Some [3;3;3])
assert (M.get ~inj:inj_str 3 m = None)</code></pre><p>change of API, the map is last argument to make piping with <code class="code">|&gt;</code> easier since 0.16.</p><ul class="at-tag"><li><span class="at-tag since">Since</span>: 0.9</li></ul><div class="spec type" id="type-injection"><a href="#type-injection" class="anchor"></a><div class="def type"><code><span class="keyword">type </span>'a injection</code><code></code><code></code></div><div class="doc"><p>An accessor for values of type 'a in any map. Values put
in the map using a key can only be retrieved using this
very same key.</p></div></div><div class="spec val" id="val-create_inj"><a href="#val-create_inj" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>create_inj : unit <span class="keyword">&#8209;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-injection">injection</a></code></div><div class="doc"><p>Return a value that works for a given type of values. This function is
normally called once for each type of value. Several keys may be
created for the same type, but a value set with a given setter can only be
retrieved with the matching getter. The same key can be reused
across multiple maps (although not in a thread-safe way).</p></div></div><div class="spec module-type" id="module-type-S"><a href="#module-type-S" class="anchor"></a><div class="def module-type"><code><span class="keyword">module type </span><a href="module-type-S/index.html">S</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></div><div class="doc"></div></div><div class="spec module-type" id="module-type-ORD"><a href="#module-type-ORD" class="anchor"></a><div class="def module-type"><code><span class="keyword">module type </span><a href="module-type-ORD/index.html">ORD</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></div><div class="doc"></div></div><div class="spec module" id="module-Make"><a href="#module-Make" class="anchor"></a><div class="def module"><code><span class="keyword">module </span><a href="Make/index.html">Make</a> : <span class="keyword">functor</span> (<a href="Make/argument-1-X/index.html">X</a> : <a href="index.html#module-type-ORD">ORD</a>) -&gt; <a href="index.html#module-type-S">S</a><span class="keyword"> with </span><span class="keyword">type </span><a href="Make/index.html#type-key">key</a><span class="keyword"> = </span><a href="Make/argument-1-X/index.html#type-t">X.t</a></code></div><div class="doc"></div></div></body></html>