gpt4 book ai didi

c# - 构建要在 C# 中使用的 F# 库

转载 作者:太空狗 更新时间:2023-10-29 17:42:37 31 4
gpt4 key购买 nike

假设我有以下功能。

let rec fib n =
match n with
| 1 | 2 -> 1
| n -> fib(n-1) + fib(n-2)

如何将这段代码编译成 dll,以便从 C# 中使用它?

我同时使用单声道(在 Mac OS X 中)和 Visual Studio 2010。

已添加

我添加了以下内容来创建命名空间。

namespace MyMath.Coremodule public Process=

And fsc --target:library facto.fs gives me facto.dll.

The C# code to use this code as follows.

using System;
using MyMath.Core;

class TestFSharp {
public static void Main() {
int val = MyMath.Core.Process.fib(10);
Console.WriteLine(val);
}
}

dmcs/r:facto.dll testf.cs 给我 tesetf.exe。

最佳答案

好吧,如果你把它放在 Program.fs 文件中,并将它编译成 library (使用 --target:library),然后它将在 C# 中显示为

Program.fib(5)

另见 call F# dll in C#

但是,如果您计划将 F# 代码公开给 C#,则可能需要使用命名空间和类型。查看F# Component Design Guidelines了解更多。

关于c# - 构建要在 C# 中使用的 F# 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3898655/

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