Aller au contenu principal
Nicolas Cousin Tech SolutionsNicolas Cousin Tech Solutions
Module 1 of 7

Prerequisites and Setup

The problem this module solves

In C#, to try out a single line of logic — check whether x % 2 = 0 returns what you expect, or verify the signature of a LINQ method — you need a project, a Main method, dotnet run, and a wait for a full compilation. Even with a unit test already in place, that's a full round trip for every attempt.

F# offers a shortcut with no direct C# equivalent: an interactive session, dotnet fsi, where you type an expression and get its value and type immediately, with no project and no prior compilation. This is the tool you'll use for every exercise in this path — not a side gadget, but the primary workbench for the seven modules that follow.

Checking that the .NET SDK is available

dotnet fsi is part of the .NET SDK: if dotnet already works for your C# projects, you already have it. Still, check which versions are installed:

dotnet --list-sdks

Expected output — one or more lines like this:

8.0.100 [/usr/share/dotnet/sdk]
9.0.306 [/usr/share/dotnet/sdk]
10.0.100 [/usr/share/dotnet/sdk]

It doesn't matter how many versions you have or which one is newest: what matters is that at least one line shows up, with no "command not found" error. If that's the case, your existing installation is enough for this entire path — no separate F# version is required, it ships with the .NET SDK itself.

Starting your first session

In a terminal, run:

dotnet fsi

After a few seconds of startup, you get a prompt waiting for your input (the version number shown may differ from yours, that's not significant):

Microsoft (R) F# Interactive version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

>

This is a REPL — Read, Evaluate, Print, Loop: you type an expression, it's evaluated immediately, and the result is displayed. Unlike a compiled C# project, nothing needs to be structured into methods or a class beforehand.

The ;; rule

A single rule governs everything you'll type into dotnet fsi: every block of code must end with a double semicolon ;; to be evaluated. Until you've typed it, fsi assumes you're still writing a multi-line entry and keeps waiting for more.

Exercise — your first command in fsi

In the fsi session you left open, type exactly this and submit it:

let square x = x * x;;

Expected output — fsi displays the type it inferred for the function you just created (the exact formatting, with or without spaces around the :, depends slightly on the version, but the meaning is the same):

val square: x: int -> int

Now call this function:

square 12;;

Expected output:

val it: int = 144

it is a special name fsi assigns to the result of the last evaluated expression when you haven't given it a name yourself. You can reuse it on the next line if needed — it's only an interactive-session convenience, not a construct you'll find in compiled F# code.

Quitting the session

When you're done, type:

#quit;;

or just close the terminal — none of your definitions need to be saved for the rest of this path: you'll simply restart dotnet fsi for each module.

What you just did

You checked that the required .NET SDK is available on your machine, started a dotnet fsi session, defined your first F# function, and observed how fsi displays the inferred type and the result of an evaluation. This is the routine you'll repeat for every module in this path.

In the next module, you'll dig into what fsi just half-revealed: how let binds a name to a value or a function, and how the compiler infers a type like x: int -> int without you writing it anywhere.

Check your understanding

You type `let square x = x * x` in an open `dotnet fsi` session, but nothing appears — the prompt just keeps waiting. What's the most likely cause?

After typing `square 12;;`, fsi displays `val it: int = 144`. What exactly does `it` represent in this output?

On a machine where `dotnet --list-sdks` already shows lines like 9.0.306 [...], do you need to install F# separately before you can use dotnet fsi?

Want to hear about the next modules?

The Academy stays free and open-access, no sign-up required. If you'd just like to be notified by email when a new module ships, here you go — no obligation, unsubscribe anytime with one click.