Skip to content
LumenaryAcademy

Lumenary CS · Programming languages

F#

A functional-first language for .NET: immutable data, types that model the problem, pipelines of small functions, and full access to the .NET ecosystem.

F# (say "F sharp") is a functional-first, statically typed language that runs on .NET. It grew out of the ML family of languages, especially OCaml, and was created by Don Syme at Microsoft Research in Cambridge; its first release appeared in 2005. F# code is concise and expression-based, values are immutable by default, and the compiler infers almost every type, so programs read almost like scripts while keeping the safety of static types. It is used for financial modelling and trading systems, data analysis, scientific and engineering computation, domain-heavy business software, web services, and tooling, and it interoperates fully with C# and every .NET library.

This course is for anyone who has finished the Start level of Lumenary CS or has equivalent experience: you know what a variable, a loop and a function are, in any language. No previous functional programming is assumed. It goes from interactive scripts to functions and pipelines, records and discriminated unions, pattern matching, collections, options and results, type inference and units of measure, computation expressions and async code, interoperation with C#, and the tools F# developers use, ending with a complete program. It teaches F# 10 on .NET 10, the long-term-support release.

To run the examples, install the .NET 10 SDK from the official download page; F# is included. Save a program as hello.fsx and run it with dotnet fsi hello.fsx, or type dotnet fsi to explore interactively. There is no official online playground; the community's Fable REPL runs F# in the browser by compiling it to JavaScript, which is fine for most short examples. Every complete program in these lessons was run with F# Interactive from the .NET 10 SDK, and the output shown is the output it printed.

AI-draftedAwaiting review by a computer scientist
  • Chloe · The Designer
    “Why is the language built this way?”
  • Margaret · The Profiler
    “What does it print, and what does it cost?”
  • Gideon · The Language Lawyer
    “What exactly does the language guarantee?”

Foundations · 3 lessons

Thinking in expressions

Run scripts with F# Interactive, bind immutable values, write and compose functions, and model data with records, unions and pattern matching.

  1. 1First steps with F#Where F# comes from, what "functional-first" means, and your first scripts in F# Interactive. 50 min
  2. 2Functions, pipelines and compositionCurried functions, partial application, the pipe operator, recursion and tuples. 55 min
  3. 3Records, unions and pattern matchingModelling a problem with types that say exactly what can exist, and taking values apart safely. 60 min

Practice · 3 lessons

Data, errors and types

Process data with lists, arrays, sequences, maps and sets; handle missing values and failures with options and results; and put type inference, generics and units of measure to work.

  1. 4Lists, arrays, sequences, maps and setsF#'s collections, the modules of functions that work on them, and how to choose between them. 60 min
  2. 5Options, results and errorsMissing values and failures as ordinary data, railway-oriented pipelines, validation, and where exceptions still belong. 60 min
  3. 6Type inference, generics and units of measureHow F# works out your types, when to help it, generic and inline code, units the compiler checks, and F#'s object-oriented side. 60 min

Professional · 2 lessons

F# in production

Use and build computation expressions for async and tasks, work hand in hand with C# and .NET libraries, and build, format and test a complete project.

  1. 7Computation expressions, async and interopThe syntax behind seq, async and task, writing your own builder, concurrent code, and working hand in hand with C#. 65 min
  2. 8Tooling, testing and a complete projectThe F# toolchain as professionals use it, example-based and property-based tests, and a small language implementation in idiomatic F#. 70 min

Further reading and resources

  • fsharp.org · F# Software FoundationThe community's home page, with guides, learning resources and links to the language design process.
  • F# documentation · MicrosoftThe official guide, tour, style guide and language reference.
  • F# language specification · F# Software FoundationThe specification, with links to the RFCs that describe each newer feature.
  • fsharp/fslang-designWhere new language features are proposed and specified as RFCs.
  • Download .NET · MicrosoftThe official SDK installers; F# is included.
  • Fable REPLA community playground that compiles F# to JavaScript and runs it in the browser.
  • The early history of the F# language · Don Syme · 2020The designer's own account, written for the History of Programming Languages conference (HOPL IV).