Actually, that one's fairly easy: you want a Monad when it makes sense to nest things like this. Indeed, my traditional handwave explanation is that, if you find yourself wanting a for comprehension like the above, and can describe exactly how it would work, you're about 3/4 of the way to being able to write the Monad in question. (That's how I learned it in the first place.)
More precisely, Monads are a formalism for a *sequential* type, where you need to deal with the first value, which gives you enough to compute the second, which gives you enough to compute the third. That's as opposed to Applicatives, which describe a *parallel* type, where you can compute two values separately and then combine their results together.
But I don't really plan on talking about that a lot here: mostly, that sort of stuff goes into my professional blog instead, and that's mostly focused on Dotty at the moment. I only did the Monad tutorial here because Monica asked, and I'm pretty practiced at teaching the subject by now. (This is actually a *highly* compressed version of a training module that I wrote for corporate use...)
(no subject)
Date: 2019-05-07 02:13 am (UTC)More precisely, Monads are a formalism for a *sequential* type, where you need to deal with the first value, which gives you enough to compute the second, which gives you enough to compute the third. That's as opposed to Applicatives, which describe a *parallel* type, where you can compute two values separately and then combine their results together.
But I don't really plan on talking about that a lot here: mostly, that sort of stuff goes into my professional blog instead, and that's mostly focused on Dotty at the moment. I only did the Monad tutorial here because Monica asked, and I'm pretty practiced at teaching the subject by now. (This is actually a *highly* compressed version of a training module that I wrote for corporate use...)