等效于 F# 结构元组的 fst 和 snd?

Wal*_*lly 7 f#

如果我使用参考元组,则编译:

let plot(x: int, y: int) = ()
let point = 3, 4
plot(fst point, snd point)
Run Code Online (Sandbox Code Playgroud)

但是,如果我使用结构元组...

let plot(x: int, y: int) = ()
let point = struct (3, 4)
plot(fst point, snd point)
Run Code Online (Sandbox Code Playgroud)

...我收到编译器错误, One tuple type is a struct tuple, the other is a reference tuple

我该怎么办?

Ast*_*sti 5

有一个ToTuple()扩展方法System.TupleExtensionsValueTuple<T1, T2...>

你可以打电话:

plot (point.ToTuple())
Run Code Online (Sandbox Code Playgroud)

至于fst, snd,它们必然会System.Tuple<>,所以也许你可以定义一个替代方案:

let fstv struct (a,_) =  a
let sndv struct (_,b) =  b
Run Code Online (Sandbox Code Playgroud)