You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5 lines
2.1 KiB

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>PhysEqual (infer.IStdlib.PhysEqual)</title><link rel="stylesheet" href="../../../odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 1.5.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> <a href="../../index.html">infer</a> &#x00BB; <a href="../index.html">IStdlib</a> &#x00BB; PhysEqual</nav><h1>Module <code>IStdlib.PhysEqual</code></h1></header><dl><dt class="spec value" id="val-shallow_equal"><a href="#val-shallow_equal" class="anchor"></a><code><span class="keyword">val</span> shallow_equal : <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool</code></dt></dl><aside><p>Helpers function to enforce physical equality.</p><p>Let suppose <code>construct/deconstruct</code> is a 1-level-allocation OCaml construction/deconstruction, such as variant type, tuple or record construction. Instead of writing</p><pre><code class="ml">let a = deconstruct a0 in
let b = deconstruct b0 in
let res = f a b in
if phys_equal res a then a0 else if phys_equal res b then b0 else construct res</code></pre><p>Simply write</p><pre><code class="ml">PhysEqual.optim2 ~res:(construct (f a b)) a0 b0 </code></pre></aside><dl><dt class="spec value" id="val-optim1"><a href="#val-optim1" class="anchor"></a><code><span class="keyword">val</span> optim1 : <span>res:<span class="type-var">'a</span></span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dt class="spec value" id="val-optim2"><a href="#val-optim2" class="anchor"></a><code><span class="keyword">val</span> optim2 : <span>res:<span class="type-var">'a</span></span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt></dl></div></body></html>