This is an example of using F# library from C#. The following steps show how to create a F# library and use it from a C# console application.
% dotnet new sln -o FsCsHybrid
% cd FsCsHybrid
% dotnet new classlib -lang "F#" -o LibFs
% dotnet new console -lang "C#" -o AppCs
% tree
.
├── AppCs
│ ├── AppCs.csproj
│ ├── Program.cs
│ └── obj
├── FooProj.sln
└── LibFs
├── LibFs.fsproj
├── Library.fs
└── obj
% dotnet add AppCs/AppCs.csproj reference LibFs/LibFs.fsproj
% cd AppCs
% vim Program.cs
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello C#");
LibFs.Say.hello("F#");% dotnet run Program.cs
Hello C#
Hello F#
% cd ../LibFs
% touch Camera.fs
% vim Camera.fs
module CameraModule
// Greatest Common Divisor (GCD)
let rec gcd :
int32->int32->int32 =
fun a b ->
match b with
| 0 -> a
| _ -> gcd b (a % b)
// camelCase is the convention in F#
let getBaseRatio :
int32->
int32->
int32*int32 =
fun width height ->
let div = gcd width height
width / div, height /div
% vim LibFs.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="Library.fs" />
<Compile Include="Camera.fs" />
</ItemGroup>
</Project>
% cd ../AppCs
% dotnet run Program.cs
Hello C#
Hello F#
width : height = 16 : 9
https://learn.microsoft.com/en-us/dotnet/fsharp/get-started/get-started-command-line