Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# generics generic construct requires that the type 'struct (Guid * int)' have a public default constructor

I have a interface in C# with method with this return type:

Task<(Guid, int)?>

I need to implement this interface in F# and if I am not mistaken this should be equivalent in F#:

Task<Nullable<ValueTuple<Guid, int>>>

Unfortunately when I compile I get this message:

generic construct requires that the type 'struct (Guid * int)' have a public default constructor

I have found some similar questions and looks like solution is usage of [<CLIMutable>] attribute. But that's not something what I can do with System.ValueTuple. Is there a way to use Nullable ValueTuple in F#?

like image 302
Michal Avatar asked Jun 19 '18 17:06

Michal


People also ask

What does ⟨F⟩ mean?

This sound is usually considered to be an allophone of /h/, which is pronounced in different ways depending upon its context; Japanese /h/ is pronounced as [ɸ] before /u/. In Welsh orthography, ⟨f⟩ represents /v/ while ⟨ff⟩ represents /f/. In Slavic languages, ⟨f⟩ is used primarily in words of foreign (Greek, Latin, or Germanic) origin.

What does the letter F mean in math?

In countries such as the United States, the letter "F" is defined as a failure in terms of academic evaluation. Other countries that use this system include Saudi Arabia, Venezuela, and the Netherlands. In the hexadecimal number system, the letter "F" or "f" is used to represent the hexadecimal digit fifteen (equivalent to 15 10 ).

What does F stand for in the Etruscan alphabet?

In the Etruscan alphabet, 'F' probably represented /w/, as in Greek, and the Etruscans formed the digraph 'FH' to represent /f/.

Is the letter F doubled at the end of words?

It is often doubled at the end of words. Exceptionally, it represents the voiced labiodental fricative / v / in the common word "of". F is the twelfth least frequently used letter in the English language (after C, G, Y, P, B, V, K, J, X, Q, and Z ), with a frequency of about 2.23% in words.


1 Answers

I think this is a compiler bug in F#. You might want to open an issue on the F# GitHub page and report this behavior. The reason I suspect it is a compiler bug is that I can make it work by simply unboxing struct (System.Guid, int) to ValueTuple<System.Guid, int>, which should already be equivalent types. Here's how I made it work in a sample, which may serve as a viable workaround for you as well, until someone more familiar with the F# compiler can let you know if it is a genuine bug or not:

open System
open System.Threading.Tasks

type ITest =
    abstract member F: unit -> Task<Nullable<ValueTuple<Guid, int>>>

type T () =
    interface ITest with
        member __.F () =
            let id = Guid.NewGuid()
            let x = Nullable(struct (id, 0) |> unbox<ValueTuple<Guid, int>>)
            Task.Run(fun () -> x)

(T() :> ITest).F().Result
like image 194
Aaron M. Eshbach Avatar answered Oct 09 '22 20:10

Aaron M. Eshbach