tags:

views:

218

answers:

1

I'm getting an issue with the F# powerpack quotation evaluation.

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 true as you would expect. The second is false. Is this a bug, or am I missing something?

+6  A: 

This looks like a bug to me. Someone from the F# team will probably give a clear answer on this :-). In the meantime, here is a simple workaround that you can use - The problem seems to be with the compilation of the = operator. You can define your own operator (or a function) and call this operator from the quoted code:

let (><) a b = 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 a wrong call to the standard = operator, this will generate code that calls your custom operator (which then runs the comparison as a standard, correctly compiled F# code), so this gives the expected result.

Tomas Petricek
Where can I report this bug? I like your workaround, though it sadly won't work in my situation.
justin
Brian (http://stackoverflow.com/users/19299/brian) from the F# team is an active StackOverflow user/addict :-) so your posting here is probably enough, but you can also report F# bugs to `fsbugs (at) microsoft (dot) com`.
Tomas Petricek
For bugs in the powerpack, please report them on the powerpack's codeplex site: http://fsharppowerpack.codeplex.com/WorkItem/List.aspx
Brian