Skip to content
LumenaryAcademy

Lumenary CS · Programming languages

Haskell

A pure, lazy, statically typed functional language whose ideas shaped a generation of programming languages, from a first program to professional practice.

Haskell is a general-purpose functional programming language, first defined in 1990 by a committee of researchers who wanted one shared, open, lazy functional language. Functions in Haskell are pure: given the same arguments they always return the same result and change nothing else, and effects such as printing or reading files are values of a special type that the runtime carries out. Its type system infers most types for you and catches whole classes of mistakes at compile time. Haskell is used for compilers and language tools, financial and blockchain systems, document converters such as Pandoc, static analysers such as ShellCheck, and a good deal of research; and its ideas (type classes, monads, algebraic data types, property-based testing) have travelled into Rust, Swift, Scala, Kotlin, C# and many more.

This course is for anyone who already knows what a variable, a loop and a function are: the Start level of Lumenary CS or equivalent experience in any language. No previous functional programming is assumed. It starts with installing GHC and running a first program, works through expressions, types, functions, lists and algebraic data types, explains type classes and monads concretely rather than abstractly, and ends with laziness and performance, concurrency and testing, the tools Haskell teams use every day, and a complete small project.

To run the code, install the toolchain with GHCup, the official installer, from haskell.org/ghcup; it gives you the GHC compiler, the GHCi interactive environment and the Cabal build tool. Or try programs in the browser at the Haskell Playground. Every complete program in these lessons was run with GHC 9.14 by Lumenary's test suite, and the output shown is the output it printed. The lessons were drafted with AI assistance and are awaiting review by a human computer scientist.

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 · 4 lessons

Foundations

Install GHC, run programs and explore in GHCi, and learn the core of the language: expressions and inferred types, functions, currying and pattern matching, and lists processed with recursion and folds.

  1. 1First steps in HaskellWhere Haskell came from, what purity and laziness mean, and your first programs with GHCup, GHC and GHCi. 45 min
  2. 2Expressions, types and type inferenceEverything is an expression, every expression has a type, and the compiler works most of them out for you. 50 min
  3. 3Functions, currying and pattern matchingDefine functions by equations, take values apart with patterns and guards, and build new functions from old ones. 55 min
  4. 4Lists, recursion and foldsThe list is Haskell's everyday collection; recursion processes it, and higher-order functions and folds capture the recursion once and for all. 55 min

Practice · 3 lessons

Practice

Model data with algebraic data types and records, share behaviour across types with type classes, and write effectful programs with IO, do-notation, Maybe, Either and the Functor, Applicative and Monad classes.

  1. 5Algebraic data types and recordsModel your domain with sums and products, so that the compiler knows every shape your data can take. 55 min
  2. 6Type classes: Eq, Ord, Show, Functor, FoldableHow one function can work on many types without losing type safety, from equality and printing to mapping and folding over any container. 60 min
  3. 7IO, do-notation and monads, concretelyHow a pure language performs effects, and the small pattern, shared by IO, Maybe, Either and lists, that do-notation is built on. 60 min

Professional · 3 lessons

Professional

Control laziness to write fast programs without space leaks, run code concurrently with threads, MVars and STM, test with properties, and build a complete project with the tools Haskell teams use every day.

  1. 8Laziness, strictness and performanceHow lazy evaluation really works, why it can leak memory, and the handful of habits that keep Haskell programs fast and lean. 60 min
  2. 9Concurrency, exceptions and testingLightweight threads, MVars and software transactional memory; exceptions in IO; and testing with properties instead of examples. 65 min
  3. 10Tools, ecosystem and a complete projectHow Haskell teams build, format, lint, document and ship code, and a small calculator language built from parser combinators up. 70 min

Further reading and resources

  • Haskell.orgThe official home of Haskell: installation, documentation, community and news.
  • GHCupThe official installer and version manager for GHC, Cabal, Stack and the Haskell Language Server.
  • Haskell 2010 Language Report · Simon Marlow (editor) · 2010The language standard. GHC implements it and adds many extensions, collected into editions such as GHC2021.
  • GHC User's GuideThe compiler's manual: GHCi, flags, warnings, language extensions, profiling and the runtime system.
  • HackageThe central package archive, with the documentation of every published library, including base.
  • HoogleSearch Haskell libraries by name or by type signature.
  • Haskell PlaygroundCompile and run Haskell programs in the browser with several GHC versions.
  • Haskell documentation indexBooks, tutorials, courses and guides collected by the Haskell community.