gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:07:42 34 4
gpt4 key购买 nike

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

let plot(x: int, y: int) = ()
let point = 3, 4
plot(fst point, snd point)

但是,如果我使用结构元组...
let plot(x: int, y: int) = ()
let point = struct (3, 4)
plot(fst point, snd point)

... 我收到编译器错误, One tuple type is a struct tuple, the other is a reference tuple
我该怎么办?

最佳答案

There's a ToTuple() extension methodSystem.TupleExtensionsValueTuple<T1, T2...> .

你可以打电话:

plot (point.ToTuple())

至于 fst , snd ,他们一定会 System.Tuple<> ,所以也许你可以定义一个替代方案:
let fstv struct (a,_) =  a
let sndv struct (_,b) = b

关于f# - 等效于 F# 结构元组的 fst 和 snd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60711493/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com