Building Efficient Programs
So far in this book, we’ve spent most of our time focused on designing programs at a high level, and making use of the features Haskell gives us to build useful abstractions. In most cases, we’ve been relying on the compiler to generate code that’s “fast enough” while we focus on designing an application that’s easy to write and maintain. Unfortunately, compilers aren’t perfect, and we often have opportunities to change our implementation to get better performance from our programs. You’ve already seen a few small examples of writing code to be more mindful of performance requirements, like when you learned about space leaks and bang patterns .
In this chapter, you’ll build a text processing library that can be used to implement spellchecking on large text documents. As we work through building this library, we’ll run across several examples of patterns we can use for improving the performance of Haskell programs. By the end of the chapter, you’ll have learned how to write programs with performance in mind, profile applications to find bottlenecks, and be able to strategically deploy some micro-optimizations to improve the performance of the most critical parts of your applications. The exercises at the end of this chapter will give you an opportunity to take the library you’ve built and integrate it into the HCat application you built in chapter 8 .