How to create an F# / dotnet 8 Replit Instance

Date: 2024-04-17 | create | tech | fsharp | dotnet | replit |

Replit is a simple, powerful way to spin up code instances in the cloud. This makes experimenting with small, shareable scripts super easy and I use it all the time to demonstrate small programs here in the Lab.

Replit has a ton of official code templates for different languages including F#. Unfortunately some of these templates aren't always up-to-date, lagging the mainstream language ecosystem. At time of writing, the official F# Replit template is stuck on dotnet 7.

In this post we'll go over how to create a Replit instance with F# on Dotnet 8.

Just want to start coding with F# 8? Fork my F# / Dotnet 8 Replit instance.

Create a Replit with F# / Dotnet 8

Replit runs nixOS which allows you to configure the dependencies (to some degree) the instance runs with - provided you know how to use nix. I don't but X/csheridan162 does and was kind enough to give me some pointers.

The .replit file configures how the instance will run - the main file, the run command, environment variables, etc. To upgrade from F# 7 to 8 we needed to update to the dotnet 8 SDK which required updating the nix.channel field to stable-23_11 because dotnet 8 wasn't available on previous versions.

Full .replit file:

run = ["dotnet", "run"]
entrypoint = "main.fs"
hidden = ["bin", "obj"]

[nix]
channel = "stable-23_11"

[env]
DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "true"

[gitHubImport]
requiredFiles = [".replit", "replit.nix"]

The replit.nix file is where we can configure which dependencies to install on the system - kinda like a package.json or .fsproj. To upgrade from F# 7 to 8 we needed to update to the dotnet 8 SDK which we did by changing pkgs.deps to pkgs.dotnet-sdk_8.

Full replit.nix file:

{ pkgs }: {
    deps = [
        pkgs.dotnet-sdk_8
    ];
}

Now that our system was setup to handle Dotnet 8 we needed to upgrade the F# project to use dotnet 8. We can do this by changing the TargetFramework field in our .fsproj.

Full .fsproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <RootNamespace>my-project</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="main.fs" />
  </ItemGroup>

</Project>

Finally we could run the boilerplate code and see if it worked. We used the existing F# template boilerplate which just runs and prints "Hello World from F#!"

Full main.fs code:

open System

[<EntryPoint>]
let main argv =
    printfn "Hello World from F#!"
    0 // return an integer exit code

Next

I've reached out to Replit on X and created a support forum ticket to try and get the official F# and C# templates updated to dotnet 8. Please go vote for those so we can get them prioritized!

Q: What other kinds of F# / dotnet tutorials would you find useful? This helps me build a useful roadmap of Shares.

If you liked this post you might also like:

Want more like this?

The best / easiest way to support my work is by subscribing for future updates and sharing with your network.