.net Tuple.Create在F中#

.net Tuple.Create在F中#,.net,f#,tuples,base-class-library,.net,F#,Tuples,Base Class Library,我注意到F#中的System.Tuple.Create方法有一个非常奇怪的行为。查看时,它指示返回类型为System.Tuple。但是,在F#中使用此方法时,除了Tuple.Create(T)之外的所有重载都将返回'T1*'T2。显然,调用Tuple构造函数将返回Tuple。但是我不明白Tuple.Create的返回类型在F#中是如何不同的。F#(一个语法元组)的元组类型被编译为System.Tuple。因此,它们在.NET级别是相同的类型,但对于F#type系统,它们是不同的类型:语法元组的类

我注意到F#中的
System.Tuple.Create
方法有一个非常奇怪的行为。查看时,它指示返回类型为
System.Tuple
。但是,在F#中使用此方法时,除了Tuple.Create(T)之外的所有重载都将返回
'T1*'T2
。显然,调用
Tuple
构造函数将返回
Tuple
。但是我不明白
Tuple.Create
的返回类型在F#中是如何不同的。

F#(一个语法元组)的元组类型被编译为
System.Tuple
。因此,它们在.NET级别是相同的类型,但对于F#type系统,它们是不同的类型:语法元组的类型与
system.tuple的类型不匹配,但它们的运行时类型相同

您可以在中找到详细说明


newsystem.tupleInterest示例;虽然语法元组与互操作上的
System.Tuple
兼容,但F#拒绝编译
System.Tuple(1,1)=(1,1)
。我不知道这在实践中是如何引起问题的,但这是一个相关的问题,所以我删除了我的答案以支持这一点。@vandroy如果需要,您可以使用Equals覆盖:
System.Tuple(1,1).Equals((1,1))
let x = new System.Tuple<_,_>(2,3) // Creates a Tuple<int,int>
let y = System.Tuple.Create(2,3)   // Creates a syntactic tuple int * int

let areEqual = x.GetType() = y.GetType() // true

let f (x:System.Tuple<int,int>) = ()
let g (x:int * int) = ()

let a = f x
let b = g y

// but

let c = f y 
//error FS0001: The type 'int * int' is not compatible with the type 'Tuple<int,int>'

let d = g x
// error FS0001: This expression was expected to have type int * int but here has type Tuple<int,int>