I wonder if there is any difference in how the two features are implemented under the hood? I.e. Aren’t just code quotations built on top of the old good expression trees?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The two types are quite similar, but they are represented differently.
Quotations are designed in a more functional way. For example
foo a bwould be represented as a series of applicationsApp(App(foo, a), b)Quotations can represent some constructs that are available only in F# and using expression trees would hide them. For example there is
Expr.LetRecursiveforlet recdeclarationsQuotations were first introduced in .NET 3.0. Back then expression trees could only represent C# expressions, so it wasn’t possible to easily capture all F# constructs (quotations can capture any F# expression including imperative ones).
Quotations are also designed to be easily processible using recursion. The
ExprShapemodule contains patterns that allow you to handle all possible quotations with just 4 cases (which is a lot easier than implementing visitor pattern with tens of methods in C#).When you have an F# quotation, you can translate it to C# expression tree using FSharp.Quotations.Evaluator. This is quite useful if you’re using some .NET API that expects expression trees from F#. As far as I know, there is no translation the other way round.