The Book of Types
The Book of Types
The Book of Types

This book is 35% complete

Last updated on 2018-09-23

About the Book

Table of Contents



1 Variance


Lifting Restrictions

2 Working with Types

2.1 Type Scoping

2.2 Type Applications

2.3 Ambiguous Types

3 Constraints, Type Equalities and GADTs

3.1 Introduction

3.2 GADTs

3.3 Heterogeneous Lists

4 Rank-N Types

4.1 Introduction

4.2 Ranks

4.3 The Nitty Gritty Details

4.4 The Continuation Monad


Computing at the Type-Level

5 Existential Types

5.1 Existential Types and Eliminators

5.1.1 Dynamic Types

5.1.2 Generalized Constraint-Kinded Existentials

5.2 Scoping Information with Existentials

6 Roles

6.1 Coercions

6.2 Roles

7 Terms, Types and Kinds

7.1 The Kind System

7.2 Data Kinds

7.3 Promotion of Built-In Types

7.4 Type-Level Functions

8 Associated Type Families

8.1 Building Types from a Schema

8.2 Generating Associated Terms

8.3 Ambiguous Types and Non-Injectivity

9 First Class Families

9.1 Defunctionalization

9.2 Type-Level Defunctionalization

9.3 Working with First Class Families

9.4 Ad-Hoc Polymorphism

10 Custom Type Errors

11 Indexed Monads

11.1 Definition and Necessary Machinery

11.2 Linear Allocations

12 Dependent Types

12.1 Overview

12.2 Ad-Hoc Implementation

12.3 Generalized Machinery

12.4 The Singletons Package

12.5 Dependent Pairs

12.5.1 Structured Logging


Pragmatic Patterns for the Working Haskell Programmer

13 Generics

13.1 Generic Representations

13.2 Deriving Structural Polymorphism

13.3 Using Generic Metadata

13.4 Performance

13.5 Kan Extensions

14 Extensible Data

14.1 Introduction

14.2 Open Sums

14.3 Open Products

14.4 Overloaded Labels

15 Higher Kinded Data

15.1 What is Higher Kinded Data?

15.2 OOP Class/Instances

About the Author

Sandy Maguire
Sandy Maguire

Sandy might best be described somewhere between independent researcher and voluntarily-unemployed bum. At the ripe old age of 27 he decided to quit his highly-lucrative engineering job and decide to focus more on living than on grinding for the man. It's what you might call a work in progress.

He regularly writes about Haskell at

The Leanpub 45-day 100% Happiness Guarantee

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

See full terms...

Write and Publish on Leanpub

Authors and publishers use Leanpub to publish amazing in-progress and completed ebooks, just like this one. You can use Leanpub to write, publish and sell your book as well! 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. It really is that easy.

Learn more about writing on Leanpub