I can convert a quotation of type Expr<'a -> 'b> to a Linq expression via the following snippet:
/// Converts a F# Expression to a LINQ Lambda
let toLambda (exp:Expr) =
let linq = exp.ToLinqExpression() :?> MethodCallExpression
linq.Arguments.[0] :?> LambdaExpression
/// Converts a Lambda quotation into a Linq Lamba Expression with 1 parameter
let ToLinq (exp : Expr<'a -> 'b>) =
let lambda = toLambda exp
Expression.Lambda<Func<'a, 'b>>(lambda.Body, lambda.Parameters)
Now I want to convert a quotation of type Expr<'a * 'b -> 'c> or maybe even Expr<'a -> 'b -> 'c> to a Linq Lambda Expression of type Expression<Func<'a,'b'c>>.
How can I do this?
Regards,
forki
I’m not sure if this is directly supported by the LINQ modules available in the F# PowerPack. However, you can implement your own post-processing of the LINQ expression produced by F# libraries to turn it into a C# lambda function of the usual form:
The following function takes a LINQ expression which is constructed as multiple nested
LambdaExpressionexpressions of a single parameter (that is, the structure produced by F# translator) and returns a list of parameters and body of the inner-most expression:Now you can use it to get an ordinary
Funcdelegate out of type such asint -> int -> int -> intlike this: