Question evaluation quotes F #

I have a problem evaluating PowerPack F # quotes.

open Microsoft.FSharp.Linq.QuotationEvaluation let print x = System.Console.WriteLine(sprintf "%A" x) type record = { x:int; y:int } let val1 = { x = 1; y = 1; } let val2 = { x = 1; y = 1; } let result = val1 = val2 print result let quote = <@ let value1 = { x = 1; y = 1; } let value2 = { x = 1; y = 1; } let result2 = value1 = value2 result2 @> print (quote.EvalUntyped()) 

The first result is correct, as expected. The second lie. Is this a mistake, or am I missing something?

+4
source share
1 answer

It looks like a mistake to me. Someone from the F # team is likely to give a clear answer to this :-). At the same time, this is an easy workaround that you can use. The problem is compiling the = operator. You can define your operator (or function) and call this operator from the quoted code:

 let (><) ab = a = b let quote = <@ let value1 = { x = 1; y = 1; } let value2 = { x = 1; y = 1; } let result2 = value1 >< value2 result2 @> print (quote.EvalUntyped()) 

Instead of generating an incorrect call to the standard operator = , it will generate code that calls your user-defined operator (which then starts the comparison as standard, correctly compiled F # code), so this gives the expected result.

+7
source

Source: https://habr.com/ru/post/1302535/


All Articles