Guide to Haskell Performance and Optimization

2 days

A course for developers who have made their first steps in Haskell and written a few programs, and who now want to take a look beyond the surface of Haskell and really get the details of how things are implemented.

It is part of the beauty of Haskell that you typically do not have to think too hard about performance. You can write code in a concise and declarative way, and still have it perform fast.

Sometimes, however, it pays off to know more about how programs run. Choosing the right data structure can make the difference between a program that runs instantaneous or one that runs forever. Making programs either too strict or too lazy can cause space leaks, which may not only result in too much memory being used (which can be very bad for long-running processes), but also result in more work for the garbage collector and make everything slower.

In this course, we’ll take a look at how Haskell (and GHC) implement things internally. We’ll discuss the internal representation of data on the heap, what exactly lazy evaluation means and how it works, how the compiler translates Haskell code to a target language via several internal representations, what you can and cannot reasonably expect the compiler to do, and how you can tweak the optimizer behaviour by using compiler pragmas such as inlining annotations and rewrite rules.

Despite all the low-level concept discussions, we will keep track of the high-level goals: to wrap certain performance-critical parts of the code in a high-level interface, so that you do not need to expose ugly details on the surface, but can write beautiful programs that scale. For this, the course will look at existing widely used and highly optimized libraries and take a look at how they are implemented internally. The course will also work through several carefully crafted hands-on exercises and examples to deepen the understanding of the concepts discussed and to illustrate common pitfalls and corner cases.

This course is designed such that Fast Track to Haskell covers all its prerequisites. However, the course is likely to be enjoyed more by participants who already have gained some practical experience in writing Haskell code.


The course includes the following topics:

  • Common Haskell data structures and their performance characteristics, such as lists, sequences, finite maps, hash maps, byte strings, text and arrays.

  • Unboxed types and the tradeoffs between boxed and unboxed types.

  • Lambda calculus and evaluation strategies; the differences between call-by-value, call-by-name and call-by-need (lazy evaluation).

  • GHC’s compilation process and its intermediate language: Core, STG and C- -, with an emphasis on understanding Core.

  • Strictness analysis and space leaks.

  • Debugging tools such as time and space profiling.

  • How the inliner works and how it can be tweaked. How custom rewrite rules work.

  • Some interesting optimizations such as lambda lifting, (stream) fusion and worker-wrapper.


The base price of this course is GBP 3000 (single lecturer) or GBP 4500 (two lecturers). The base price excludes VAT and any other applicable taxes as well as travel costs which depend on the location of the course venue.

We generally recommend two lecturers, as it will allow a better ratio between lecturers and participants during the exercises, and will thereby encourage particpants to ask more questions. We strongly encourage to use two lecturers if there are more than five participants.

We offer on-site consulting in combination with on-site courses at a reduced daily rate.

If you are interested in this course, or for more information, please e-mail us with as many details as possible.

Why Well-Typed

Our teachers have more than a decade of experience with Haskell, functional programming, compiler design, and related areas. They have been training people at all experience levels, both in academia and in industry.

The insight they brought about how to think in Haskell was great and something that would be very difficult to get from a book or online.

— Anonymous