Here's what can be done in C# -
var two = 2;
System.Linq.Expressions.Expression<System.Func<int, int>> expr = x => x * two;
expr.Compile().Invoke(4); // returns 8
I wish to do the precise equivalent in F#. Here's what I tried, but did not compile -
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
Perhaps predictably, compilation fails on line 2 with the following error -
"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>>
^^^^^^^^^^^^^^^^