Monads (CIS194 Wk 12) by Matt Peddie
Monads (CIS194 Wk 12)
By Matt Peddie
Over the last couple of yorgey lectures, we have seen how the Applicative class allows us to idiomatically handle computations which take place in some sort of "special context" -- for example, taking into account possible failure with Maybe, multiple possible outputs with [], consulting some sort of environment using ((->) e), or construct parsers using a "combinator" approach, as in the homework.
However, so far we have only seen computations with a fixed structure, such as applying a data constructor to a fixed set of arguments. What if we don't know the structure of the computation in advance -- that is, we want to be able to decide what to do based on some intermediate results?