The book that takes you from a competent Haskell programmer to one whose compiler does the work for you.

About the Book

Hi there. My name is Sandy Maguire and you might know me from my blog where I write about type-level programming in Haskell.

This book came to be when I realized that learning type-level programming was harder than it needed to be. While the information was available, it wasn't organized. The best way to learn this stuff was to read through dozens of blog posts—each of which described a small piece of the puzzle—and attempt to synthesize it for yourself.

I knew we could do better.

Without further ado, I'd like to introduce Thinking with Types: Type-Level Programming in Haskell—the comprehensive guide to unleashing the power of Haskell's type-system. In it, we'll cover topics like erasing boilerplate with GHC.Generics, building extensible data-types, and how to generate error messages meant for humans when things go wrong.

What You'll Learn


  • The Algebra Behind Types
  • Cardinalities
  • Isomorphisms
  • Sums, Products and Exponentials
  • The Curry–Howard Isomorphism
  • Canonical Representations of Types
  • Terms, Types and Kinds
  • Data Kinds
  • Constraint Kinds
  • Writing Type Level Functions

Advanced Types

  • How Types are Scoped
  • Type Applications
  • Ambiguous Types
  • Non-Injectivity
  • Constraints
  • GADTs and Type-Equalities
  • Writing HLists
  • Rank-N Types
  • Existential Types
  • The ST Trick
  • Roles

Type-Level Programming

  • Associated Type Families
  • First Class Type Families
  • Defunctionalization
  • Extensible Sums and Products
  • Overloaded Labels
  • Custom Type Errors
  • GHC.Generics
  • Kan Extensions
  • Indexed Monads
  • Linear Types
  • Dependent Types

Interested, but not sure if it's for you? Read the first few chapters and see what you think!