25
Write your first code in F#
F# is an open-source, cross-platform programming language that makes it easy to write succinct, performant, robust, and practical code.
- LEARN module The first F# module of many was just published on LEARN, check it out Take your first steps with F#
- LEARN module The second module just published. Write your first F# programs
- F# docs
There are many language features and aspects of the F# language that make it easy to be productive when writing code:
- Succinct: You write less code with F# that's also expressed in a clear manner.
- Performant: F# comes with built-in parallelism and concurrency. It also uses the fact that it's part of the .NET runtime to speed things up.
- Robust: There are language constructs that makes the code fault tolerant and robust like immutable by default, null value management and more.
- Supports multiple programming paradigms: F# lets you choose the patterns and practices most effective for solving problems by providing strong support for functional and object programming paradigms.
There are a few things you need to get started.
- .NET SDK. You need to install the .NET SDK to be able to buiild, run, test and also create F# projects. You can find the F# SDK install here
- Ionide. It's a VS Code plugin. It's not necessary to install, but it will give you things like Intellisense, tooltips, codelens, error highlight and more.
You can start writing F# by using the REPL called FSI, you can also scaffold an F# project using the dotnet
executable.
You create a project using dotnet
like so:
dotnet new console --language F# -o MyFSharpApp
Then you get a project with files:
- Program.fs, your entrypoint file
- MyFSharpApp.csproj, your project file that contains everything it needs to know to build the project like dependencies for example.
Here you have the code of Program.fs. Itt contains the functions from()
and main()
. main()
is the entry point of the app, as seen by [<EntryPoint>]
.
open System
// Define a function to construct a message to print
let from whom =
sprintf "from %s" whom
[<EntryPoint>]
let main argv =
let message = from "F#" // Call the function
printfn "Hello world %s" message
0 // return an integer exit code
The from()
function takes the arg whom
and the function body prints a string using the function sprintf
.
- LEARN module The first F# module of many was just published on LEARN, check it out Take your first steps with F#
- LEARN module The second module just published. Write your first F# programs
- F# docs
25