|// The problem with Run is that the expression is begin rebuilt and then compiled everytime, potentially too expensive|
|let Run : int -> int = fun y -> Query.range(0,1000)|
||> Query.filter(fun x -> x > y)|
|// The problem with BuildFunc is that it doesn't compile :)|
|let BuildFunc : int -> int = Query.range(0,1000)|
||> Query.filter(fun x -> x > VAR) // VAR should be the input parameter to the compiled func|
Check this https://github.com/nessos/LinqOptimizer/blob/master/src/LinqOptimizer.FSharp/FSharpQuery.fs
palladin's snippet should theoretically work except it will not. The problem is the way that the F# compiler produces expressions trees (seems like a conversion from Quotations to Expression) and especially nested expressions. Of course in C# this overload of compile will work fine. Consider the following snippet.
The second expression corresponds to palladin's Query.compile(.... Query.filter(...lambda...)....).