Sunday, 6 May 2012

How do you evaluate a quotation in F#?

You can evaluate an F# quotation using the Eval extension member provided by the FSharp.PowerPack.Linq DLL as follows:
#r "FSharp.PowerPack.Linq.dll"
open Linq.QuotationEvaluation

let f = <@2 + 3@>

Note that you must open the Linq.QuotationEvaluation namespace to make this extension member available.
There is also a Compile extension member that returns a suspension but it does not appear to improve performance.

No comments: