A set of challenges for jump starting your understanding of monads.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
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:
repRandom
(sequence
)generalB
(liftM2
)From set 2:
chain
(=<<
)yLink
(liftM2
)combine
(join
)From set 3:
allCombs
(liftM2
)allCombs3
(liftM3
)combStep
(ap
)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
.