Represents a rank-1 polymorphic type scheme:
$$ \forall \alpha_1\dots\alpha_n.\, \tau $$
The quantified variables in vars are type variable references which appear
inside the body type and are universally quantified at the outermost level
(prenex form).
At each use site, schemes are instantiated into fresh monotypes via
instantiate/1, which replaces every quantified variable with a fresh
reference. This is the mechanism that allows polymorphic constants like
$=^\alpha$ (with scheme $\forall\alpha.\,\alpha\to\alpha\to o$) to be used at
different types within the same formula.
Monotypes can be lifted into trivial schemes (with empty vars) using
mono/1.
Example
iex> alpha = make_ref()
iex> scheme = TypeScheme.new([alpha], Type.new(alpha, alpha))
iex> match?(%TypeScheme{vars: [^alpha]}, scheme)
true
Summary
Functions
Returns the set of free type variables in the scheme. This is defined as the set of free type variables in the body without the bound type variables.
Generalizes a given type by binding free type variables in a scheme.
Instantiates the bound type variables in the given type scheme with fresh type variables.
Constructs a trivial type scheme representing the given monotype.
Constructs a type scheme binding the type variables vars in the (possibly
polymorphic) type body.
Types
@type t() :: %ShotDs.Data.TypeScheme{ body: ShotDs.Data.Type.t(), vars: [ShotDs.Data.Type.variable_id()] }
Elixir type of a (rank-1 polymorphic) type scheme.
Functions
@spec free_type_vars(t()) :: MapSet.t(ShotDs.Data.Type.variable_id())
Returns the set of free type variables in the scheme. This is defined as the set of free type variables in the body without the bound type variables.
@spec generalize(ShotDs.Data.Type.t(), MapSet.t(ShotDs.Data.Type.variable_id())) :: t()
Generalizes a given type by binding free type variables in a scheme.
@spec instantiate(t()) :: ShotDs.Data.Type.t()
Instantiates the bound type variables in the given type scheme with fresh type variables.
@spec mono(ShotDs.Data.Type.t()) :: t()
Constructs a trivial type scheme representing the given monotype.
@spec new([ShotDs.Data.Type.variable_id()], ShotDs.Data.Type.t()) :: t()
Constructs a type scheme binding the type variables vars in the (possibly
polymorphic) type body.