
Haskell Brain Teasers: Exercise Your Mind
Author(s): Rebecca Skinner (Author), Michael Swaine (Editor), Miki Tebeka (Series Editor)
- Publisher: Pragmatic Bookshelf
- Publication Date: March 24, 2026
- Edition: 1st
- Language: English
- Print length: 100 pages
- ASIN: B0FVF2TNT8
- ISBN-13: 9798888651902
Book Description
Deepen your Haskell knowledge, sharpen your functional programming skills, and just have fun with 25 functional programming puzzles to tie your brain in knots.
Challenge and exercise your functional programming knowledge by tackling these 20 fun, funky, and functional puzzles on Haskell programming topics such as lazy evaluation, Haskell syntax, type classes, and the type system. Gain new insight into why Haskell is the way it is. Build mind-bending self-referential and circular data structures, unpick the seams of reality with unsafePerformIO, build enhanced DSLs with QualifiedDo, and refactor without fear of the dreaded monomorphism restriction. Review or get introduced to Haskell’s common quirks such as the unary minus and pattern guards while mastering newer language features up to GHC 9.12, including linear arrows and Or Patterns.
Employ powerful techniques and recognize common pitfalls as you solve fiendish puzzles across five different topic areas.
Don’t sleep on the lazy evaluation puzzles: they’ll challenge you to predict the behavior of programs that rely on laziness in unexpected ways. Think syntax and language extensions puzzles should be easy? Think again as you deal with the perversity of the unary minus operator, or puzzles based on new extensions like QualifiedDo. Prepare to be perplexed with Type Class puzzles on ad-hoc polymorphism, deriving strategies, and record fields. Want more? Try mixing classic ambiguous type puzzles with advanced new features like linear types.
After trying your hand at each puzzle, read through the solution to get more insight into key Haskell features, and use the references to build a reading list to dive deeper into new areas of the language.
Editorial Reviews
Editorial Reviews
About the Author
Excerpt. © Reprinted by permission. All rights reserved.
Introduction
Haskell’s reputation is all about purity, safety, expressiveness, and power. It’s a language admired by many, but loved by few. For those of us who do love it, the joy comes from its flexibility and the ease of expressing our ideas without compromise.
Haskell’s flexibility is one of its greatest strengths: A predictable and composable grammar gives developers the latitude to write code with nuance and style, and language extensions allow Haskell to continually raise the bar for what an industrial-strength language can do. At the same time, Haskell’s flexibility can be an obstacle to fluency. When a language pragma changes the semantic meaning of your code or you first learn that “an expression” really means yes, any expression, your reaction is more likely to be frustration than joy.
This book is here to help. As you work through short, focused puzzles you’ll gain a clear, intuitive understanding of Haskell and start to see it as a cohesive whole. And don’t forget to stop and smell the rose trees.
Who This Book Is For
It’s for you if you are a Haskell expert, are somewhat familiar with Haskell, or are just generally interested in functional programming.
How to Read this Book
Each puzzle begins with a small self-contained Haskell program intended to run with GHC 9.12 or later using the GHC2024 language version. All required imports and language extensions are included in the puzzles and examples.
When you read the puzzle, try to predict what will happen when you compile and run the program. For example, will it:
- Run normally and print something to the screen?
- Run slowly or use a lot of memory?
- Fail to compile due to a syntax or type error?
- Hang indefinitely in an infinite loop or deadlock?
- Crash with a runtime exception?
Example Code and Tests
The sample code for this book includes standalone files for each puzzle, full example code, unit and property tests, and a complete, reproducible nix environment you can use to build and run the code. It’s available on the Pragmatic Bookshelf website.[1] There, you can download the code, participate in discussions, and post issues if needed.
Puzzle Organization and Difficulty
You can work through the puzzles in any order. They’re grouped thematically, based on which part of the language they focus on. For example, Part I focuses on challenges related to lazy evaluation, while puzzles in Part IV will lean more into reasoning about types.
Puzzles in each part are organized roughly from easiest to hardest. Since difficulty varies depending on your personal experience and background, you might run across an easier puzzle that’s challenging for you- or you might find a difficult puzzle quite easy. If you do find a puzzle that you can’t solve now, feel free to skip ahead and come back to it later.
Footnotes
Wow! eBook

