Books to improve my thinking with generics (aka parametric polymorphism)

I'm a fairly experienced Swift programmer and I feel that my object-oriented foundations for programming sometimes don't let me explore the full power of Swift's generics. As I write new code to solve practical challenges, I feel like I could benefit from learning some basic concepts of thinking in types and generics, two most powerful devices of swift as a language.

I know that there's an official Swift book and couple of great WWDC talks (Generics and Protocols oriented programming). Are there any good books, not necessarily for Swift that you personally found useful building your "thinking in types" muscle?

3 Likes

I would recommend Types and Programming Languages, by Benjamin Pierce, which is kind of the bible in type theory. Although it's aimed more at academia than industry, it's full of examples that are perfectly understandable to any experienced software developer.

Chapters 22 to 28 will cover most of the theory surrounding polymorphism à la Swift. The features that Swift offers through protocols and conformance constraints is mostly treated in chapter 26 (bounded quantification). The chapters on higher-order types will give you a taste of what awesome things a future, more powerful type system could do (also be sure to check the Generics Manifesto).

Apart from books you may also want to have a look at some of Philip Wadler's keynotes. He's one of the minds behind Haskell, a very opinionated person about programming languages and an eccentric yet great communicator. While his talks usually revolve around Java and Haskell, I'm sure you'll find interesting insights to better "think in types".

7 Likes

Appreciate you taking time to share the recommendations. Looking froward to watching and reading them all!