class documentation

class Substitutions: (source)

View In Hierarchy

A domain of instantiated type variables.

>>> d = Substitutions()
>>> assert len(list(d.variables())) == 0
>>> t1 = TypeVariable()
>>> t2 = TypeVariable()
>>> v1 = Type('int')
>>> v2 = Type('float')
>>> d.bind(t1, v1)
>>> dd = d.copy()
>>> d.bind(t2, v2)
>>> d
<Substitutions:
@TypeVar... -> int
@TypeVar... -> float
<UnionFind:
elts=['@TypeVar...', 'int', '@TypeVar...', 'float'],
siz=[1, 1, 1, 1],
par=[0, 1, 2, 3],
nb_rm=[0, 0, 0, 0],
removed=[],
free=[],
n_elts=4,n_comps=4>
>
>>> d.bind(t1, t2)
>>> d
<Substitutions:
@TypeVar... -> float
@TypeVar... -> float
<UnionFind:
elts=['@TypeVar...', 'int', '@TypeVar...', 'float'],
siz=[2, 2, 1, 1],
par=[0, 1, 0, 1],
nb_rm=[0, 0, 0, 0],
removed=[],
free=[],
n_elts=4,n_comps=2>
>
>>> dd.bind(t1, t2)
>>> dd
<Substitutions:
@TypeVar... -> int
@TypeVar... -> int
<UnionFind:
elts=['@TypeVar...', 'int', '@TypeVar...'],
siz=[2, 1, 1],
par=[0, 1, 0],
nb_rm=[0, 0, 0],
removed=[],
free=[],
n_elts=3,n_comps=2>
>
Method __init__ Undocumented
Method __repr__ Undocumented
Method bind Add a new binding for a variable.
Method copy Copy the substitutions into a new instance.
Method mark Create a mark of this substitutions, to be applied with restore.
Method rep Get the representant of this type.
Method restore Restore a mark previously created with mark.
Method type This will return the complex type associated with a given type variable.
Method variables Iterate over all type variables in the domain.
Method _merge_unify Undocumented
Instance Variable _graph Undocumented
Instance Variable _uf Dans la structure de données Union-find, les classes d'équivalence ne contiennent soit que des variables soit que des termes complexes. Pour passer d'une variable à un terme complexe, on utilise les pointeurs éventuels qui sont dans le graphe.
def __init__(self): (source)

Undocumented

def __repr__(self) -> str: (source)

Undocumented

def bind(self, var: TypeVariable, value: Type): (source)

Add a new binding for a variable.

def copy(self) -> Substitutions: (source)

Copy the substitutions into a new instance.

Create a mark of this substitutions, to be applied with restore.

def rep(self, t: Type) -> int: (source)

Get the representant of this type.

def restore(self, mark: MarkedSubstitutions): (source)

Restore a mark previously created with mark.

def type(self, var: TypeVariable) -> Type | None: (source)

This will return the complex type associated with a given type variable.

def variables(self) -> Iterator[TypeVariable]: (source)

Iterate over all type variables in the domain.

def _merge_unify(self, t1: Type, t2: Type) -> Type: (source)

Undocumented

Undocumented

Dans la structure de données Union-find, les classes d'équivalence ne contiennent soit que des variables soit que des termes complexes. Pour passer d'une variable à un terme complexe, on utilise les pointeurs éventuels qui sont dans le graphe.