Class AlphaRenamer
Eliminates name conflicts for variables in expression trees. Because variables get represented by ParameterExpression nodes which have referential identity, syntactic name conflicts can occur.
Inheritance
Namespace: System.Linq.CompilerServices
Assembly: Nuqleon.Linq.CompilerServices.dll
Syntax
public static class AlphaRenamer : Object
Examples
Consider the following definitions of the well-known K and I combinators:
K = \x.\y.x
I = \x.x
The following function is a valid representation of KI = (\x.\y.x)(\x.x) = \y.\x.x
var x1 = Expression.Parameter(typeof(int), "x");
var x2 = Expression.Parameter(typeof(int), "x");
var ki = Expression.Lambda(Expression.Lambda(x2, x2), x1); // x => x => x
The following function is a valid representation of K = \x.\y.x
var x1 = Expression.Parameter(typeof(int), "x");
var x2 = Expression.Parameter(typeof(int), "x");
var k = Expression.Lambda(Expression.Lambda(x1, x2), x1); // x => x => x
Syntactically, both functions have an identical textual representation, requiring object identity checks to distinguish their semantic meaning.
Methods
EliminateNameConflicts(Expression)
Eliminates name conflicts for bound variables in the given expression, by substituting conflicting occurrences for fresh parameter expressions.
Declaration
public static Expression EliminateNameConflicts(Expression expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | expression | Expression to eliminate name conflicts in. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | Expression without name conflicts for bound variables. Global variables are not affected. |