Let's say I have the following function.
let rec fib n =
match n with
| 1 | 2 -> 1
| n -> fib(n-1) + fib(n-2)
How can I compile this code into dll so that it's used from C#?
I use both mono (in Mac OS X) and Visual Studio 2010.
I added the following to make namespace.
namespace MyMath.Core module 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 gives me tesetf.exe.
Well, if you put this in the file Program.fs, and compile it into a library (with --target:library
), then it would appear from C# as
Program.fib(5)
See also call F# dll in C#
However if you plan to expose F# code to C#, you may want to uses namespaces and types. See the F# Component Design Guidelines for more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With