Lesson 7. Rules for recursion and pattern matching

After reading lesson 7, you’ll be able to

  • Understand the definition of a recursive function
  • Learn the rules for writing recursive functions
  • Walk through examples of recursive function definitions
  • Use basic pattern matching to solve recursive problems

One of the first challenges of writing practical code in a functional language is that because you don’t have state changes, you also don’t have common looping functions that rely on changing state, such as for, while, and until loops. All iteration problems have to be solved through recursion. For many programmers, this is a terrifying thought, as recursion typically brings up memories of headache-inducing problem solving. Thankfully, you can ...

Get Get Programming with Haskell 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.