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.

A Missed Generalization

We just found an equivalence between generalB and yLink. In Set 2 we implemented yLink in terms of link without using any cases. But in Set 1 you might not have implemented generalB in terms of genTwo. Go back and look at your generalB implementation and if you didn’t write it in terms of genTwo, do that now and call it generalB2. Doing this should get rid of the state threading between generators.

Re-implement repRandom in terms of generalA, genTwo, and mkGen. Note that by using generalA, genTwo and mkGen you should not need to have a seed variable in your code for repRandom anywhere.

Previous Page - Next Page