Wie erstelle ich einen Linq-Ausdrucksbaum mit einem F # -Lambda?

Folgendes kann in C # ausgeführt werden:

var two = 2;
System.Linq.Expressions.Expression<System.Func<int, int>> expr = x => x * two;
expr.Compile().Invoke(4); // returns 8

Ich möchte das genaue Äquivalent in F # machen. Folgendes habe ich versucht, aber nicht kompiliert:

let two = 2
let expr = (fun x -> x * two) : System.Linq.Expressions.Expression<System.Func<int, int>>
expr.Compile().Invoke(4) // desired to return 8

Möglicherweise schlägt die Kompilierung in Zeile 2 mit dem folgenden Fehler fehl:

"This function takes too many arguments, or is used in a context where a function is not expected."
let expr = (fun x -> x * two) : System.Linq.Expressions.Expression<System.Func<int, int>>
            ^^^^^^^^^^^^^^^^

Antworten auf die Frage(1)

Ihre Antwort auf die Frage