Course

Haskell from the ground up

Values, functions and types that keep their promises

  • Beginner
  • 12 chapters
  • 206 min read

Learn Haskell by writing it: values and types, functions you define yourself, lists and the patterns that take them apart, recursion in place of loops, map and filter and the fold, tuples and zip, list comprehensions, Maybe for searches that can fail, types of your own with the abilities you ask for, Either for failures that explain themselves, and a sales report at the end that uses all of it.

What You'll Learn

  • Write a program as the value main and print lines of output with it
  • Tell the small types apart and turn any value into text with show
  • Define a function with a type line that promises what goes in and out
  • Build a list with the colon and take it apart by matching on its shape
  • Choose an answer with guards, and know why if needs an else branch
  • Repeat work by calling a function on a smaller piece, with a base case
  • Name helpers and values close to where they are used with where and let
  • Replace hand-written walks with map, filter and foldr
  • Bundle values as tuples and walk two lists side by side with zip
  • Describe a list you want with a comprehension and a condition
  • Answer a search that can fail with Maybe, and say why it is not null
  • Give your own data a type, ask for Show, Eq and Ord, and sort by a field
  • Report a failure with Either, carrying the reason back to the caller
  • Build a formatted report from records, a sort and a set of totals

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 changes state

Course Content

  1. 01
    Values, types and the first program

    What runs when you press Run, how a value becomes text with show, and the small set of types every line in this course is built from.

    Beginner · 14 min read

    Not started
  2. 02
    Functions you write yourself

    How a function definition is written, how you apply a function to its arguments, and why a type line is a promise worth writing down.

    Beginner · 15 min read

    Not started
  3. 03
    Lists, and matching on their shape

    The list as the one collection in the language, the colon that builds it, the pattern that takes it apart, and why text is a list of characters.

    Beginner · 16 min read

    Not started
  4. 04
    Guards and readable choices

    Yes and no values, comparisons, and the two ways to choose an answer: a chain of guards or a single if expression.

    Beginner · 14 min read

    Not started
  5. 05
    Recursion is the loop

    There is no for and no while: a function calls itself on a smaller piece of the work until a base case answers, with where naming the helpers.

    Intermediate · 18 min read

    Not started
  6. 06
    map, filter and the fold

    Functions are values you can pass around, so three small helpers replace most hand-written walks: change every value, keep some, or boil a list down to one answer.

    Intermediate · 18 min read

    Not started
  7. 07
    Tuples, zip and paired data

    Bundling a few values together when they belong together, walking two lists side by side with zip and zipWith, and reading the halves of a pair.

    Intermediate · 16 min read

    Not started
  8. 08
    List comprehensions

    Describing the list you want instead of the steps that build it: a generator says where the values come from, and a condition keeps some of them.

    Intermediate · 16 min read

    Not started
  9. 09
    Maybe: when there may be no answer

    A lookup that can fail should say so in its type: Maybe holds either nothing at all or a real answer, and you take it apart before you use it.

    Advanced · 18 min read

    Not started
  10. 10
    Your own types, and what deriving gives you

    data builds a type of your own out of named fields, deriving asks for the abilities the type should have, and a lowercase name in a signature means any type at all.

    Advanced · 20 min read

    Not started
  11. 11
    Either: errors that carry a message

    When a failure needs to explain itself, Either brings the reason back as a value: one half for the problem, one half for the answer, both written in the type.

    Advanced · 19 min read

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

    A report built from everything in the course: records with a derived order, a sort by one field, totals that aggregate, and formatted lines printed by the map that runs an action.

    Advanced · 22 min read

    Not started