F # tuple, System.Tuple and collection - type constraint mismatch?

The last two lines in the following code got a compiler error?

open System let s = new System.Collections.Generic.Stack<Tuple<int, int>>() s.Push( 1, 2) // The type ''a * 'b' is not compatible with the type 'Tuple<int,int>' s.Push(Tuple.Create(1, 2)) 

s.Push(Tuple.Create(1, 2)) error s.Push(Tuple.Create(1, 2))

  Type constraint mismatch.  The type 
     '' a * 'b'    
 is not compatible with type
     'Tuple'
 The type '' a * 'b' is not compatible with the type 'Tuple'
 type Tuple =
   static member Create: item1: 'T1 -> Tuple + 7 overloads
 Full name: System.Tuple
+5
source share
1 answer

Although the F # tuples are presented with System.Tuple in compiled form, they are not considered a โ€œpseudonymโ€ for it in terms of logical language.

int * int does not match System.Tuple<int, int> with respect to the F # compiler.

Just use the F # tuple syntax for the Stack generic argument, and it will work:

 let s = new System.Collections.Generic.Stack<int * int>() s.Push( 1, 2) 
+3
source

All Articles