Acknowledgments....10
Introduction....11
Who This Book Is For....12
How to Read This Book....13
Example Code and Tests....14
Puzzle Organization and Difficulty....15
Code Formatting....16
Part I. Lazy Evaluation....17
Puzzle 1. Looking for a Needle in a Stack of Infinities....18
Puzzle 2. Haskell for Very Full Stack Developers....24
Puzzle 3. Say Cheese....31
Puzzle 4. Diving Head First into a Bottomless Pit....38
Puzzle 5. The Least You Can Possibly Do....44
Puzzle 6. Do You Even Lift?....50
Part II. Syntax and Language Extensions....57
Puzzle 7. Oh Em Dash....58
Puzzle 8. Playing with Matches....64
Puzzle 9. Many Roads, One Destination....70
Puzzle 10. A View of the Future....77
Puzzle 11. FQDN - Fully Qualified do Notation....82
Part III. Type Classes....91
Puzzle 12. Traversing Tuples....92
Puzzle 13. A Slightly Off-White Hat....99
Puzzle 14. If At First You Dont Succeed, Trie, Trie Again....106
Puzzle 15. A Nice Recipe for Soup....112
Puzzle 16. Field Theory....118
Part IV. The Type System....126
Puzzle 17. Round-Trip Tickets....127
Puzzle 18. A Grand Un-Unified Theory....134
Puzzle 19. Non-Functional Dependencies....142
Puzzle 20. Time Flies Like an Arrow....149
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.