如果我使用参考元组,则编译:
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
我该怎么办?
有一个ToTuple()扩展方法中System.TupleExtensions的ValueTuple<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)