Are there any documents or examples out there on how one can extend/add new keywords to query expressions? Is this even possible?
For example, I’d like to add a lead/lag operator.
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.
In addition to the query builder for the Rx Framework mentioned by @pad, there is also a talk by Wonseok Chae from the F# team about Computation Expressions that includes query expressions. I’m not sure if the meeting was recorded, but there are very detailed slides with a cool example on query syntax for generating .NET IL code.
The source code of the standard F# query builder is probably the best resource for finding out what types of operations are supported and how to annotate them with attributes.
The key attributes that you’ll probably need are demonstrated by the
whereclause:The
CustomOperationattribute defines the name of the operation. The (quite important) parameterMaintainsVariableSpaceallows you to say that the operation returns the same type of values as it takes as the input. In that case, the variables defined earlier are still available after the operation. For example:Here, the variables
pandnameare still accessible afterwherebecausewhereonly filters the input, but it does not transform the values in the list.Finally, the
ProjectionParameterallows you to say thatp.UnitValue > 100.0Mshould actually be turned into a function that takes the context (available variables) and evaluates this expression. If you do not specify this attribute, then the operation just gets the value of the argument as in:Here, the argument
10is just a simple expression that cannot use values inp.