The Monad Challenges

A set of challenges for jump starting your understanding of monads.

Outline

Set 1: Random Numbers

Set 2: Failing Computations

Set 3: Combinations

Set 4: Common Abstraction

Set 5: Do Notation

This project is maintained by mightybyte

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Revisiting Other Generic Functions

Now that we have our monad type class and an understanding of what motivated it, go back and rewrite the generic functions from sets 1, 2, and 3 using your Monad type class. But since we’re rewriting them generically we need to give them new names. Here are the functions that you should rewrite and the new names that you should use. From set 1:

From set 2:

From set 3:

You only need to write liftM2 once. But instead of using Gen, Maybe, or [] you use m in its place with the Monad m type class constraint. Try to do this set without looking at the code you used before. Just copy all the type signatures and redo the work, but this time do everything in terms of return and bind.

Previous Page - Next Page