This chapter covers:
- Classifying program entities such as terms, types, and kinds
- Specifying code behavior with a bunch of type-level features
- Dealing with type errors
This chapter is devoted to programming at the level of types. We explore the variety of Haskell features that make it possible. As we’ve discussed earlier in this book, types help us to control software behavior and express our ideas on what the code should and shouldn’t do. Heavily typed code is highly resistant to some sorts of bugs. It also enables aggressive refactoring. If we do something wrong the Haskell type checker would report that.
We discuss features and techniques available to any Haskell programmer. While presenting them, I limit myself to elementary artificial examples. In particular, we discuss types and kinds system, data kinds, type families, generalised algebraic datatypes, and polymorphism. I conclude this chapter with ways to deal with errors while programming at type-level.
Almost everything discussed in this chapter is not standard Haskell and implemented in GHC via extensions. By the end of this chapter you will understand and be able to use all the GHC extensions from the following listing: