Recursion for Haskells
Recursion in Haskell is the main way to repeat work, since there are no loops with mutable counters. A function calls itself on a smaller input until a base case stops it. Higher-order functions such as map, filter and foldr capture common recursive patterns so you rarely write the recursion by hand.
Stage: Foundations · Part of the Haskell roadmap · Last reviewed 19 November 2026
What to learn in Recursion
- Write a recursive function with a clear base case and step
- Use map and filter to transform and select list elements
- Explain what foldr and foldl do with an accumulator
- Build new functions through partial application and composition with the dot operator
- Rewrite a recursive function using a fold
Recursion interview questions
What is the difference between foldl and foldr?
foldr processes a list from the right, replacing each cons with a function and the empty list with an initial value, so it can work on infinite lists lazily. foldl accumulates from the left and can build up unevaluated thunks, so foldl' is preferred for sums.
What is tail recursion and does it matter in Haskell?
A tail-recursive function makes its recursive call as the last action, so it can run in constant stack space. In Haskell laziness changes the picture, so the accumulator may need to be forced with seq or a bang pattern to avoid building thunks.
Where Recursion fits in the Haskell roadmap
Recursion belongs to the Foundations stage (intermediate level), which takes about 23 hours. Pure functions.
Other units in this stage
Back to the full Haskell roadmap