I want to test headOrDefault in F # on an empty array that should work like FirstOrDefault in C #. So I typed this code:
let arr = [] let res = query { for e in arr do select e headOrDefault } Console.WriteLine("{0}", (res = null))
I would expect to resget a null value.
res
But this code does not even compile. I get this compilation error:
Internal common functions are not allowed in quoted expressions. Consider adding type constraints until this function is no longer common.
The compiler underlines arrin this line as a problem:
arr
for e in arr do
Why doesn't this compile and how can I make it work (using headOrDefault)?
Thank!
[] , , , , . , [||] Array.empty.
, , , , .. , /. System.Object, ( System.Object , , -, ):
let emptyarr:System.Object list = [] let res = query { for e in emptyarr do select e headOrDefault } System.Console.WriteLine("{0}", (res = null))
let arr = [] : obj list, .
let arr = [] : obj list