Essential F#
Minimum price
Suggested price

Essential F#

About the Book

The revised edition of this book will be released as a free download on July 15, 2022. If you buy the current version, the author's royalties go to the F# Software Foundation.

This is a practical book aimed at efficiently getting you up to speed with the essentials of functional-first programming in F#. 

Everywhere you look, programming languages are gaining functional features. The problem is that it's not the individual features that make functional programmers happy, it's the way that your approach to writing software and the features work together to help you write simple code to solve interesting problems. This book will help you to discover why F# is such a popular language with those who have spent time learning its secrets. 

This book started life as a series of blog posts on my employer's website ( The sum of the content is what a developer needs to know to be able to work on one of our F# Line of Business codebases. I have improved and extended the content, upgraded the code to F# 5, and ensured that the code would run in VS Code with the ionide extension.

All of the author's royalties from this book are going to the F# Software Foundation ( to help them to support the F# community around the world.

About the Author

Ian Russell
Ian Russell

Ian Russell has over 25 years experience as a software developer in the UK. He has held many technical roles over the years but made the decision many years ago that he could do most good by remaining ‘just a software developer’. Ian works remotely from the UK for Trustbit, a software solutions provider based in Vienna, on a cloud-based GPS aggregator for a logistics company written mostly in F#. Ian’s .NET journey started with C# 1.1 in 2003 and he started playing in his own time with F# in 2010. He has been a regular speaker at UK user groups and conferences for over 11 years.

Table of Contents

  • Preface
    • Who should read this book
    • Thanks
    • About the author
  • Introduction
    • Why Choose F#?
    • What does this book cover
    • Setting up your environment
    • F# Software Foundation
    • One Last Thing
  • 1 - A simple domain modelling exercise
    • The Problem
    • Initial Version
    • Making the Implicit Explicit (1 of 2)
    • Making the Implicit Explicit (2 of 2)
    • Type Composition
    • Summary
    • Postscript
  • 2 - Function Composition
    • Theory
    • In Practice
    • Unit
    • Multiple Parameters
    • Partial Application
    • Summary
  • 3 - Null and Exception Handling
    • Null Handling
    • Interop With .NET
    • Handling Exceptions
    • Function Composition With Result
    • Summary
  • 4 - Organising Code
    • Getting Started
    • Solutions and Projects
    • Adding a Source File
    • Namespaces and Modules
    • Problem
    • Creating Unit Tests
    • Simplifying Our Code
    • Extending the Functionality
    • Adding Unit Tests for Register Customer
    • The Completed Codebase
    • Summary
  • 5 - Introduction to Collections
    • Before We Start
    • The Basics
    • Core Functionality
    • Folding
    • Grouping Data and Uniqueness
    • Practical Example
    • Summary
  • 6 - Reading Data From a File
    • Setting Up
    • Loading Data
    • Parsing Data
    • Testing the Code
    • Final Code
    • Summary
  • 7 - Active Patterns
    • Setting Up
    • Partial Active Patterns
    • Parameterized Partial Active Patterns
    • Multi-Case Active Patterns
    • Summary
  • 8 - Functional Validation
    • Setting Up
    • Solving the Problem
    • Where are we now?
    • Functional validation the F# way
    • Summary
  • 9 - Single Case Discriminated Union
    • Setting Up
    • Solving the Problem
    • Final Code
    • Record Type
    • Summary
  • 10 - Object Programming
    • Setting Up
    • Class Types
    • Interfaces
    • Object Expressions
    • Encapsulation
    • Equality
    • Summary
  • 11 - Recursion
    • Setting Up
    • Solving The Problem
    • Tail Call Optimisation
    • Expanding the Accumulator
    • FizzBuzz Using Recursion
    • Quicksort using recursion
    • Other Uses Of Recursion
    • Further Reading
    • Summary
  • 12 - Computation Expressions
    • Setting Up
    • Introducing the Problem
    • The Result Computation Expression
    • Introduction to Async
    • Computation Expressions in Action
    • Debugging Code
    • Further Reading
    • Summary
  • 13 - Introduction to Web Programming with Giraffe
    • Getting Started
    • Running the Sample Code
    • HttpHandlers and Combinators
    • Next Steps
    • Creating an API
    • Creating a Custom HttpHandler
    • Creating a View
    • Tidying up Routing
    • Reviewing the Code
    • Summary
  • 14 - Creating an API with Giraffe
    • Getting Started
    • Our Task
    • Sample Data
    • Routes
    • Handlers
    • Using the API
    • Summary
  • 15 - Creating Web Pages with Giraffe
    • Getting Started
    • Our Task
    • Configuration
    • Converting HTML To Giraffe View Engine
    • Next Stage
    • Tidying Up
    • Summary
  • Summary
    • F# Software Foundation
    • Resources
    • And Finally
  • Appendix
    • Creating Solutions and Projects in VS Code

The Leanpub 60-day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms

Do Well. Do Good.

Authors have earned$11,718,542writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF, EPUB and/or MOBI files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub