Class BetaReducer
Applies beta reduction on invocation expressions (applications) applied to lambda expressions (abstractions). Various expression tree rewrites can use this step to inline expressions in a template represented by a lambda expression.
Inheritance
Namespace: System.Linq.CompilerServices
Assembly: Nuqleon.Linq.CompilerServices.dll
Syntax
public static class BetaReducer : Object
Examples
Consider the following expression:
Expression.Invoke(Expression.Lambda(x, x), Expression.Constant(42))
After beta reduction, the resulting expression is:
Expression.Constant(42)
Methods
Reduce(Expression)
Applies beta reduction on invocation expressions in the given expression. Only arguments of an atomic expression node type will be inlined.
Declaration
public static Expression Reduce(Expression expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | expression | Expression to apply beta reductions on. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | Expression after applying beta reductions. |
Reduce(Expression, BetaReductionNodeTypes, BetaReductionRestrictions)
Applies beta reduction on invocation expressions in the given expression, using the specified configuration flags. This is an advanced method which should be used with care when side-effects in expression trees are critical to maintain. Some configurations may lead to changes in timing and the arity of side-effects.
Declaration
public static Expression Reduce(Expression expression, BetaReductionNodeTypes nodeTypes, BetaReductionRestrictions restrictions)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | expression | Expression to apply beta reductions on. |
BetaReductionNodeTypes | nodeTypes | Flags to restrict the argument expression node types that will be inlined during beta reduction. (Default: Atoms) |
BetaReductionRestrictions | restrictions | Flags to restrict the number of uses of each argument expression during inlining. (Default: None) |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | Expression after applying beta reductions. |
ReduceEager(Expression, BetaReductionNodeTypes, BetaReductionRestrictions, Boolean)
Applies beta reduction on invocation expressions in the given expression, using the specified configuration flags, until no further reductions are possible. This is an advanced method which should be used with care when side-effects in expression trees are critical to maintain. Some configurations may lead to changes in timing and the arity of side-effects.
Declaration
public static Expression ReduceEager(Expression expression, BetaReductionNodeTypes nodeTypes, BetaReductionRestrictions restrictions, bool throwOnCycle)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | expression | Expression to apply beta reductions on. |
BetaReductionNodeTypes | nodeTypes | Flags to restrict the argument expression node types that will be inlined during beta reduction. |
BetaReductionRestrictions | restrictions | Flags to restrict the number of uses of each argument expression during inlining. |
System.Boolean | throwOnCycle | Indicates whether to throw an exception if the reduction gets stuck in a cyclic reduction (e.g. for a recursive lambda expression). If set to false, the reduction stops and the current expression is returned. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | Expression after applying beta reductions. |