Jump to ratings and reviews
Rate this book

Thinking with Types. Type-Level Programming in Haskell

Rate this book
This book aims to be the comprehensive manual for type-level programming. It's about getting you from here to there---from a competent Haskell programmer to one who convinces the compiler to do their work for them.

247 pages, ebook

Published November 9, 2018

27 people are currently reading
292 people want to read

About the author

Sandy Maguire

3 books199 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
30 (65%)
4 stars
10 (21%)
3 stars
5 (10%)
2 stars
1 (2%)
1 star
0 (0%)
Displaying 1 - 4 of 4 reviews
Profile Image for Mark Seemann.
Author 3 books484 followers
June 23, 2020
I've been dabbling with basic Haskell for years, but whenever I'd run int GADTs, type families, Generics, existential types, etc. I'd have no idea what people were writing or talking about. I'd tried to read up on some of those topics, but found the default online materials hard to follow.

Thinking with Types addresses all that in a clear and lucid way. It met me at just the right level. It does assume that you're already familiar with Haskell. It wastes no time explaining basics. For me, it was near-perfect; I only had to look up a few things here and there.

This book has been my study book since I finished The Haskell School of Music. I try to do an hour of study each morning. For the first time in years, when the hour was over, I wanted to continue (but, alas, I had to work). When I went to bed in the evening, I thought "yes, tomorrow I get to read in Thinking with Types". When I woke up in the morning, I'd think "yes, soon I'll be studying Thinking with Types again". What a contrast to The Haskell School of Music.

As usual, I'd be typing in the code as I was reading, always checking that it compiled and that I understood what was going on. The way the code is presented, it's painless to follow along in this way.

My only gripe is that as the book progressed, I found that it got so abstract that some examples would have been much appreciated. This happened to me around chapter 11 on Extensible Data. I had a hard time understanding what it was all good for.

Then the book improved again with its chapters on Generics and Indexed Monads, but then got hard to follow in the last chapter on Dependent Types. Despite my initial enthusiasm, I considered a four-star ranking, but just as I finished the book, I thought of a problem I'd been mulling over that I might be able to solve with open products. Apparently, I'd retained something from the chapter on Extensible Data, despite my frustrations with it.

I've spent the next days since I finished the book on Friday successfully developing a prototype, with help from the book. The fact that it enabled me to do that, and even based on the chapter that frustrated me the most, is a testament to its quality.

I still think a few examples could improve the latter chapters, but it's not enough to detract from a five-star rating.
Profile Image for molty cheese.
5 reviews6 followers
July 15, 2020
More like lecture notes and less like a book

Most of the explanations are really terse and do not completely explain what is going on: Why do we need this language extension? Why did we do it this way and not the other? At first the author explained everything quite clearly (or maybe I simply knew all this stuff) but somewhere around `printf` chapter the quality of the explanations suddenly dropped.

However, after a couple of months I returned to it and re-read chapters I found abstruse before and it was quite an enjoyable read -- examples (especially on Generics) were clear and "real-worldy" and I already knew most of the extensions and type-level hackery anyway.
So, yes, if I ever need to implement something I would definitely consult this book (with GHC User's Guide and maybe some related papers) on the topic. But I'm not sure whether it is a good source to actually learn the topic.

Here is an easy-to-read paper on the topic of type functions you might want to read before related chapters here. It definitely helped me.
https://www.microsoft.com/en-us/resea...

Hope this helps.
Profile Image for Matvey Aksenov.
70 reviews7 followers
November 23, 2022
Pretty basic stuff.

In Haskell, the problem with type-level programming is that it is completely unprincipled and therefore disintegrates into a pile of shit pretty much immediately (e.g., see a chapter on FCF). Unless you were very careful and thought about the ergonomics of your API a lot, nobody is going to touch your type-level chicanery with a ten-foot pole. There's hope in that DT is going to probably eventually land in GHC.

As an aside, this guy's Haskell style is insufferable.
Profile Image for Pavel.
5 reviews
March 23, 2025
The book is a compilation of type-level techniques in Haskell. First half of the book can be followed and there are explanations of what is happening and why.

Unfortunately I found the the second part of the book (starting somewhere around chapter “Extensible types”) difficult to understand, because it’s written as a blog post of someone showing pieces of code and giving their commentary to an already expert audience.

For me (as someone wanting to learn more about type-level programming) it was hard to grasp. I often found myself asking “where is this going” or “what’s the bigger picture here”.

For example in chapter 10 the author shows how ad-hoc polymorphism can be used to implement monoid operations on types. The book shows you code snippets of Mappend and Mempty aaaand .. that’s it! You are left wondering if there is some point to the type algebra or author wanted to demonstrate a complex example (but why not something simpler? and why was the chapter building up to this?) or you missed something in some code snippet or you are just too dumb to extrapolate a point the author is doing. True to its title the book makes you think (hard), but not in a good or productive way.

Also be prepared to switching to ghci or googling descriptions of various Haskell extensions.

If you want to learn about type-level programming and build your intuition from ground up look elsewhere. If you are a proficient Haskell developer looking to extend his or her portfolio with new type-level techniques in Haskell then this book could be for you.

What I expected from the book is learning how to think with types based on substantial experience of the author. What I got from the book were Haskell patterns and idioms based on types and kinds. 3 stars is a fair rating.
Displaying 1 - 4 of 4 reviews

Can't find what you're looking for?

Get help and learn more about the design.