liveBook · Manning

Chapter 7: First abstract nonsense interlude: Category theory

What you will learn in chapter 7 of Fabulous Adventures in Data Structures and Algorithms

This introduction motivates category theory as a practical, theoretical, and enjoyable way to reason about abstractions and composable operations in programming, and previews its connection to type-system variance.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction motivates category theory as a practical, theoretical, and enjoyable way to reason about abstractions and composable operations in programming, and previews its connection to type-system variance.

Key terms: abstractions, bits and bytes, variables, objects, functions, algorithms, divide and conquer, composable operations, design patterns, object-oriented programming

7.1 Category theory is generalized abstract nonsense

This section introduces categories as objects linked by morphisms and shows how covariant functors map between categories while preserving those links.

Key terms: category, objects, morphisms, identity morphism, reflexive, transitive, function, morphism, dashed arrows, covariant functor

7.2 Covariant endofunctors in the category of types

This section models C# assignment compatibility as a category and shows why a covariant generic interface such as IE<T> is a covariant endofunctor on the category of types.

Key terms: category of types, assignment-compatibility relation, morphism, posetal category, Object, Animal, IE<T>, IEnumerable<T>, covariant, out

7.3 Contravariant endofunctors in the category of types

This section uses a contravariant C# comparer interface to show how a type construction reverses assignment arrows and thus forms a contravariant endofunctor.

Key terms: contravariant interface, IC<T>, in modifier, input positions, assignment compatibility, morphism, contravariant functor, contravariant endofunctor, arrow reversal, IC<IC<T>>

7.4 Summary

This summary recaps category-theory terms and connects covariant and contravariant type interfaces to functors over assignment-compatible types.

Where this is used later

Concepts explained in this chapter

← Chapter 6: Combinatorial algorithms Chapter 8: Coloring graphs with backtracking search →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.