Exercises

Now that you’ve learned a bit about the basics of Haskell’s syntax and how to write some applications, try working through these exercises. You should be able to complete all of the following exercises using the material from this chapter, but if you find yourself stuck on an exercise, try reading ahead to the next chapter and coming back to the exercise after you’ve gotten a bit more practice thinking about how to implement programs in Haskell.

Factorials

The factorial function is a simple function that you can define recursively. You can compute the factorial of a number, n, by multiplying all of the numbers up to n:

 factorial 5 = 5 * 4 * 3 * 2 * 1 = 120

Try implementing your own factorial function. You can test your implementation ...

Get Effective 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.