moonpool/ocaml/Subst/index.html
2025-09-26 19:08:06 +00:00

20 lines
16 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Subst (ocaml.Subst)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.1.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../index.html">Index</a> &#x00BB; <a href="../index.html">ocaml</a> &#x00BB; Subst</nav><header class="odoc-preamble"><h1>Module <code><span>Subst</span></code></h1><p>Substitutions</p></header><div class="odoc-content"><p>Substitutions are used to translate a type from one context to another. This requires substituting paths for identifiers, and possibly also lowering the level of non-generic variables so that they are inferior to the maximum level of the new context.</p><p>Substitutions can also be used to create a &quot;clean&quot; copy of a type. Indeed, non-variable node of a type are duplicated, with their levels set to generic level. That way, the resulting type is well-formed (decreasing levels), even if the original one was not.</p><p>In the presence of local substitutions for module types, a substitution for a type expression may fail to produce a well-formed type. In order to confine this issue to local substitutions, the type of substitutions is split into a safe and unsafe variant. Only unsafe substitutions may expand a module type path into a generic module type.</p><div class="odoc-spec"><div class="spec type anchored" id="type-subst"><a href="#type-subst" class="anchor"></a><code><span><span class="keyword">type</span> <span>+'k subst</span></span></code></div><div class="spec-doc"><p>Type familly for substitutions</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-safe"><a href="#type-safe" class="anchor"></a><code><span><span class="keyword">type</span> safe</span><span> = </span><span>[ </span></code><ol><li id="type-safe.Safe" class="def variant constructor anchored"><a href="#type-safe.Safe" class="anchor"></a><code><span>| </span><span>`Safe</span></code></li></ol><code><span> ]</span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-unsafe"><a href="#type-unsafe" class="anchor"></a><code><span><span class="keyword">type</span> unsafe</span><span> = </span><span>[ </span></code><ol><li id="type-unsafe.Unsafe" class="def variant constructor anchored"><a href="#type-unsafe.Unsafe" class="anchor"></a><code><span>| </span><span>`Unsafe</span></code></li></ol><code><span> ]</span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> t</span><span> = <span><a href="#type-safe">safe</a> <a href="#type-subst">subst</a></span></span></code></div><div class="spec-doc"><p>Standard substitution</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-identity"><a href="#val-identity" class="anchor"></a><code><span><span class="keyword">val</span> identity : <span><span class="type-var">'a</span> <a href="#type-subst">subst</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-unsafe"><a href="#val-unsafe" class="anchor"></a><code><span><span class="keyword">val</span> unsafe : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-unsafe">unsafe</a> <a href="#type-subst">subst</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_type"><a href="#val-add_type" class="anchor"></a><code><span><span class="keyword">val</span> add_type : <span><a href="../Ident/index.html#type-t">Ident.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Path/index.html#type-t">Path.t</a> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'k</span> <a href="#type-subst">subst</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'k</span> <a href="#type-subst">subst</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_module"><a href="#val-add_module" class="anchor"></a><code><span><span class="keyword">val</span> add_module : <span><a href="../Ident/index.html#type-t">Ident.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Path/index.html#type-t">Path.t</a> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'k</span> <a href="#type-subst">subst</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'k</span> <a href="#type-subst">subst</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_modtype"><a href="#val-add_modtype" class="anchor"></a><code><span><span class="keyword">val</span> add_modtype : <span><a href="../Ident/index.html#type-t">Ident.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Path/index.html#type-t">Path.t</a> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'k</span> <a href="#type-subst">subst</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'k</span> <a href="#type-subst">subst</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-for_saving"><a href="#val-for_saving" class="anchor"></a><code><span><span class="keyword">val</span> for_saving : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-reset_for_saving"><a href="#val-reset_for_saving" class="anchor"></a><code><span><span class="keyword">val</span> reset_for_saving : <span>unit <span class="arrow">&#45;&gt;</span></span> unit</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-change_locs"><a href="#val-change_locs" class="anchor"></a><code><span><span class="keyword">val</span> change_locs : <span><span><span class="type-var">'k</span> <a href="#type-subst">subst</a></span> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Location/index.html#type-t">Location.t</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'k</span> <a href="#type-subst">subst</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-module_path"><a href="#val-module_path" class="anchor"></a><code><span><span class="keyword">val</span> module_path : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Path/index.html#type-t">Path.t</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Path/index.html#type-t">Path.t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-type_path"><a href="#val-type_path" class="anchor"></a><code><span><span class="keyword">val</span> type_path : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Path/index.html#type-t">Path.t</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Path/index.html#type-t">Path.t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-modtype_path"><a href="#val-modtype_path" class="anchor"></a><code><span><span class="keyword">val</span> modtype_path : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Path/index.html#type-t">Path.t</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Path/index.html#type-t">Path.t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-type_expr"><a href="#val-type_expr" class="anchor"></a><code><span><span class="keyword">val</span> type_expr : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Types/index.html#type-type_expr">Types.type_expr</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Types/index.html#type-type_expr">Types.type_expr</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-class_type"><a href="#val-class_type" class="anchor"></a><code><span><span class="keyword">val</span> class_type : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Types/index.html#type-class_type">Types.class_type</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Types/index.html#type-class_type">Types.class_type</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-value_description"><a href="#val-value_description" class="anchor"></a><code><span><span class="keyword">val</span> value_description : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Types/index.html#type-value_description">Types.value_description</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Types/index.html#type-value_description">Types.value_description</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-type_declaration"><a href="#val-type_declaration" class="anchor"></a><code><span><span class="keyword">val</span> type_declaration : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Types/index.html#type-type_declaration">Types.type_declaration</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Types/index.html#type-type_declaration">Types.type_declaration</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-extension_constructor"><a href="#val-extension_constructor" class="anchor"></a><code><span><span class="keyword">val</span> extension_constructor :
<span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Types/index.html#type-extension_constructor">Types.extension_constructor</a> <span class="arrow">&#45;&gt;</span></span>
<a href="../Types/index.html#type-extension_constructor">Types.extension_constructor</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-class_declaration"><a href="#val-class_declaration" class="anchor"></a><code><span><span class="keyword">val</span> class_declaration : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Types/index.html#type-class_declaration">Types.class_declaration</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Types/index.html#type-class_declaration">Types.class_declaration</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-cltype_declaration"><a href="#val-cltype_declaration" class="anchor"></a><code><span><span class="keyword">val</span> cltype_declaration :
<span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Types/index.html#type-class_type_declaration">Types.class_type_declaration</a> <span class="arrow">&#45;&gt;</span></span>
<a href="../Types/index.html#type-class_type_declaration">Types.class_type_declaration</a></span></code></div></div><p>When applied to a signature item, a substitution not only modifies the types present in its declaration, but also refreshes the identifier of the item. Effectively this creates new declarations, and so one should decide what the scope of this new declaration should be.</p><p>This is decided by the <code>scoping</code> argument passed to the following functions.</p><div class="odoc-spec"><div class="spec type anchored" id="type-scoping"><a href="#type-scoping" class="anchor"></a><code><span><span class="keyword">type</span> scoping</span><span> = </span></code><ol><li id="type-scoping.Keep" class="def variant constructor anchored"><a href="#type-scoping.Keep" class="anchor"></a><code><span>| </span><span><span class="constructor">Keep</span></span></code></li><li id="type-scoping.Make_local" class="def variant constructor anchored"><a href="#type-scoping.Make_local" class="anchor"></a><code><span>| </span><span><span class="constructor">Make_local</span></span></code></li><li id="type-scoping.Rescope" class="def variant constructor anchored"><a href="#type-scoping.Rescope" class="anchor"></a><code><span>| </span><span><span class="constructor">Rescope</span> <span class="keyword">of</span> int</span></code></li></ol></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-modtype"><a href="#val-modtype" class="anchor"></a><code><span><span class="keyword">val</span> modtype : <span><a href="#type-scoping">scoping</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Types/index.html#type-module_type">Types.module_type</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Types/index.html#type-module_type">Types.module_type</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-signature"><a href="#val-signature" class="anchor"></a><code><span><span class="keyword">val</span> signature : <span><a href="#type-scoping">scoping</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Types/index.html#type-signature">Types.signature</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Types/index.html#type-signature">Types.signature</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-signature_item"><a href="#val-signature_item" class="anchor"></a><code><span><span class="keyword">val</span> signature_item :
<span><a href="#type-scoping">scoping</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Types/index.html#type-signature_item">Types.signature_item</a> <span class="arrow">&#45;&gt;</span></span>
<a href="../Types/index.html#type-signature_item">Types.signature_item</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-modtype_declaration"><a href="#val-modtype_declaration" class="anchor"></a><code><span><span class="keyword">val</span> modtype_declaration :
<span><a href="#type-scoping">scoping</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Types/index.html#type-modtype_declaration">Types.modtype_declaration</a> <span class="arrow">&#45;&gt;</span></span>
<a href="../Types/index.html#type-modtype_declaration">Types.modtype_declaration</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-module_declaration"><a href="#val-module_declaration" class="anchor"></a><code><span><span class="keyword">val</span> module_declaration :
<span><a href="#type-scoping">scoping</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Types/index.html#type-module_declaration">Types.module_declaration</a> <span class="arrow">&#45;&gt;</span></span>
<a href="../Types/index.html#type-module_declaration">Types.module_declaration</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-compose"><a href="#val-compose" class="anchor"></a><code><span><span class="keyword">val</span> compose : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Composition of substitutions: apply (compose s1 s2) x = apply s2 (apply s1 x) *</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Unsafe"><a href="#module-Unsafe" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Unsafe/index.html">Unsafe</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Lazy"><a href="#module-Lazy" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Lazy/index.html">Lazy</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div></div></body></html>