【发布时间】:2021-07-01 00:25:12
【问题描述】:
我是 F# 新手,我正在尝试执行一个静态 C# 函数,该函数接受来自 F# 文件/代码的多个参数。
我有一个包含 C# 项目和 F# 项目的单一解决方案。
C# 项目
来自 C# 文件的代码:
using ...
namespace Factories
{
public static class FruitFactory
{
public static string GiveMe(int count, string fruitname)
{
...
...
return ... (string) ...
}
}
}
F# 项目
F# 文件中的代码:
open System
open Factories
[<EntryPoint>]
let main argv =
let result = FruitFactory.GiveMe 2 "Apples"
printfn "%s" result
printfn "Closing Fruit Factory!"
0
从上面的代码中,我得到代码let result = FruitFactory.GiveMe 2 "Apples"的以下错误
错误 1:
Program.fs(6, 37): [FS0001] This expression was expected to have type
'int * string'
but here has type
'int'
错误 2:
Program.fs(6, 18): [FS0003] This value is not a function and cannot be applied.
【问题讨论】:
-
如果 C# 函数只接受单个参数,则此代码完美运行,例如:如果 C# 函数为
... GiveMe(int count)而 F# 代码为... FruitFactory.GiveMe 2,则一切正常! -
您可以在FSharpForFunAndProfit.com 阅读有关函数的信息。本文介绍 F# 中的函数以及如何使用它们。我建议阅读整个“Thinking functionally”系列以了解 F# 的核心原理