Course

F# from the ground up

Values that never change, and functions that fit together

  • Beginner
  • 12 chapters
  • 211 min read

Learn F# by writing it: values and printfn, let bindings that cannot be assigned to, functions applied one argument at a time, pipes and composition, lists walked with map and filter, folds and sorts and groups, tuples and pattern matching, records with named fields, discriminated unions with a match that must be complete, options in place of null, strings and format strings, and a sales report at the end that uses all of it.

What You'll Learn

  • Write a script as a list of lines and print with printfn and its placeholders
  • Tell int, float, string, bool and char apart, and print any of them with %A
  • Define a value with let and know that nothing can change it afterwards
  • Use a function as a value, with partial application and a type annotation where one is needed
  • Turn nested calls into a pipeline with |> and name a pipeline with >>
  • Walk a list with List.map and List.filter instead of writing a loop
  • Boil a list down with List.fold, and reach for sumBy, sortBy, countBy and groupBy first
  • Group values as tuples and take them apart in a let or a match
  • Choose between cases with match, and order the specific patterns before the broad one
  • Declare a record, create one with its field names, and copy one with `with`
  • Model a fixed set of cases with a discriminated union and handle every case
  • Answer a search that can fail with option, Option.map and defaultValue
  • Join and split text with String.concat and Split, and align columns in a format string
  • Build a report from records, a sort, a group and a set of formatted lines

Prerequisites

  • No programming experience needed — the first chapter starts at the first value
  • If you know another language, the biggest difference is that nothing here is assigned to twice

Course Content

  1. 01
    Values, types and printfn

    What the page runs when you press Run, the five kinds of value the rest of the course is built from, and the format string that turns any of them into a line of output.

    Beginner · 14 min read

    Not started
  2. 02
    let bindings that never change

    A name in F# is a definition rather than a slot: there is nothing to assign to, so a value you read at line three still means the same thing at line thirty.

    Beginner · 15 min read

    Not started
  3. 03
    Functions and partial application

    A function is a value with parameters, written without brackets and called without commas. Give it fewer arguments than it takes and the answer is another function.

    Beginner · 16 min read

    Not started
  4. 04
    Pipes and composition

    Two small operators do most of the arranging in F#: `|>` sends a value into a function, and `>>` joins two functions into one that can be used later.

    Beginner · 16 min read

    Not started
  5. 05
    Lists and the helpers that walk them

    A list is one type repeated, written with semicolons, and `List.map` and `List.filter` replace most loops: change every value, or keep the ones that pass a test.

    Intermediate · 18 min read

    Not started
  6. 06
    Fold, sort and group

    A fold boils a list down to one answer, `sumBy` and `maxBy` are the folds you will use most, and `sortBy`, `countBy` and `groupBy` turn a list into the sections of a report.

    Intermediate · 18 min read

    Not started
  7. 07
    Tuples and pattern matching

    A tuple groups values by position, and `match` takes a value apart by shape. Together they replace a pile of `if`s with a list of cases the compiler can check.

    Intermediate · 18 min read

    Not started
  8. 08
    Records: your own named data

    A record gives each part of a value a name and a type. You create one with its field names, copy one to change a field, and both operations leave the original exactly as it was.

    Intermediate · 18 min read

    Not started
  9. 09
    Discriminated unions and match

    A union says a value is one of a fixed set of cases, each carrying its own data. `match` takes it apart, and the compiler knows when a case has been forgotten.

    Advanced · 20 min read

    Not started
  10. 10
    Option instead of null

    A search that can fail answers `Some value` or `None`, and the type makes you deal with both. No null, no exception, no book that is not there.

    Advanced · 18 min read

    Not started
  11. 11
    Text, splitting and format strings

    Strings join with `+`, split into arrays and come back together with `String.concat`. A format string with widths is what turns values into columns a reader can scan.

    Advanced · 18 min read

    Not started
  12. 12
    Capstone: a sales report from records

    Everything in the course in one script: a record, a list of them, a sort by one field, a group by another, and formatted lines printed by the function that builds them.

    Advanced · 22 min read

    Not started