Installation, Tools and F# Interactive

2.1 Installing

Plugin / notes Ionide-fsharp (IntelliSense, CodeLens type signatures, FSI integration) Excellent built-in F# support Visual Studio (Windows) Built-in F# support FsAutoComplete (the F# language server)

# Install the .NET SDK (includes F#): https://dotnet.microsoft.com/download
dotnet --version
# macOS:  brew install --cask dotnet-sdk
# Ubuntu: sudo apt install dotnet-sdk-8.0   (or use the Microsoft package feed)
# Windows: winget install Microsoft.DotNet.SDK.8

2.2 F# Interactive (FSI)

dotnet fsi                       # REPL; end expressions with ;; then Enter
> let x = 40 + 2;;
val x: int = 42
> let square n = n * n;;
val square: n: int -> int
> square 12;;
val it: int = 144
> #help;;
> #quit;;

2.3 Scripts (.fsx)

// hello.fsx
#r "nuget: FSharp.Data"                 // reference NuGet packages directly in scripts

let name = "F#"
printfn "Hello, %s!" name
printfn $"Interpolated: {name} has {name.Length} chars"
dotnet fsi hello.fsx

2.4 Projects

dotnet new console -lang F# -o HelloApp
cd HelloApp
dotnet run
dotnet new classlib -lang F# -o MyLib
dotnet new xunit -lang F# -o MyTests
dotnet new sln -o MySolution && dotnet sln add HelloApp MyLib MyTests
dotnet add HelloApp reference MyLib
dotnet add package FSharp.SystemTextJson
dotnet build && dotnet test
// Program.fs
[<EntryPoint>]
let main argv =
    printfn "Hello from F#! Args: %A" argv
    0   // exit code
// (Top-level code without [<EntryPoint>] also works in the last file of a project)