package merlin-lib

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Ocaml_typing.SubstSource

Substitutions

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.

Substitutions can also be used to create a "clean" 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.

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.

Sourcetype +'k subst

Type familly for substitutions

Sourcetype safe = [
  1. | `Safe
]
Sourcetype unsafe = [
  1. | `Unsafe
]
Sourcetype t = safe subst

Standard substitution

Sourceval identity : 'a subst
Sourceval unsafe : t -> unsafe subst
Sourceval add_type : Ident.t -> Path.t -> 'k subst -> 'k subst
Sourceval add_module : Ident.t -> Path.t -> 'k subst -> 'k subst
Sourceval add_modtype : Ident.t -> Path.t -> 'k subst -> 'k subst
Sourceval for_saving : t -> t
Sourceval make_loc_ghost : t -> t
Sourceval reset_for_saving : unit -> unit
Sourceval change_locs : 'k subst -> Ocaml_parsing.Location.t -> 'k subst
Sourceval module_path : t -> Path.t -> Path.t
Sourceval type_path : t -> Path.t -> Path.t
Sourceval modtype_path : t -> Path.t -> Path.t

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.

This is decided by the scoping argument passed to the following functions.

Sourcetype scoping =
  1. | Keep
  2. | Make_local
  3. | Rescope of int
Sourceval compose : t -> t -> t

Composition of substitutions: apply (compose s1 s2) x = apply s2 (apply s1 x) *

Sourcemodule Unsafe : sig ... end
Sourcemodule Lazy : sig ... end
OCaml

Innovation. Community. Security.