9 Algebraic data types and pattern matching
This chapter covers
- Removing invalid states from programs
- Using algebraic data types
- Handling errors with optional values and variants
- Creating overloaded function objects
- Handling algebraic data types through pattern matching
During the course of this book, we’ve tackled a few problems the program state introduces. You’ve seen how to design software without mutable state and how to implement data structures that are efficient to copy. But we still haven’t dealt with all the problems of program state: we haven’t covered unexpected or invalid states.
Consider the following situation. Suppose you have an application that counts the total number of words on a web page. The program can start counting ...
Get Functional Programming in C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.