gpt4 book ai didi

f# - 如何选择方法的特定重载?

转载 作者:行者123 更新时间:2023-12-05 01:55:22 25 4
gpt4 key购买 nike

我正在调用一个使用重载和可选参数的 C# API。不幸的是,其中一个重载是 params object[] 并且 F# 选择它而不是我打算调用的更具体的重载。如何让 F# 选择我想要的重载?

Here's a small repro . And here is a link to the actual API .

open System
open System.Linq.Expressions

type S =
static member Foo(expression: Expression<Func<int>>, ?gg: string) =
"expression"
static member Foo([<ParamArray>] args: obj[]) =
"params array"

[<EntryPoint>]
let main argv =
// This prints "params array", but I want it to print "expression"
let result = S.Foo(fun () -> 3, "")
printfn "%s" result
0

最佳答案

要调用带有两个参数的表达式版本,您需要:

let result = S.Foo((fun () -> 3), "")

在您的代码中,您实际上已经定义了一个返回 (3, "") 元组的函数,它只是一个参数。

关于f# - 如何选择方法的特定重载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70253567/

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