Monad tutorial, part 2

Building on the foundation of the Identity Decider from Part 1, I first introduce some notation to make a monadic computation look more like a `let`. Then I explain the Maybe monad and what it tells us about how monads are meant to be used. Finally, I show what the Sequence monad does as a teaser for Part 3.

3 Responses to “Monad tutorial, part 2”

  1. bobcorrick Says:

    Thank you for posting these. It will help when I get to a later chapter in “7 languages in 7 weeks” (in about 6 months’ time…).

    I have one remark: I don’t (yet) see why the final domonad example in this session used sequence-m instead of perhaps identity-decider. From the earlier explanation “take the result of a step, assign it do a variable, execute remaining steps” it seems that it indetity-decider would have worked.

    What am I missing?

  2. bobcorrick Says:

    …seems identity-decider would have worked.” Sorry.

  3. Brian Marick Says:

    Identity-decider would pass the whole list to the next step. Sequence-m passes each element separately (so many calls vs. one).

    It’s called sequence-m because (as you’ll see), the sequence monad is composed of two functions: a decider function that looks like this:

    (concat (map remaining-steps result-of-last-step))

    … and a “patcher” function that’s needed to make that work. (I’ll say no more yet!)

Leave a Reply

You must be logged in to post a comment.