DEV Community

Discussion on: Cooking with Monads

Collapse
 
iquardt profile image
Iven Marquardt • Edited

Teaching monads by example may have its advantages but also entails its very own drawbacks. Monads are so general that every specific example you pick looks kind of arbitrarily, because you could have just as well picked another one from the thousands of possibilities.

Maybe it is a good idea to provide both, an example and an abstract decription: What a monad does on a very fundamental level is to turn an ordinary value into a computation of a specific notion. A mere collection of natural numbers [1,2,3], for instance, is turned into a prioritized choice/non deterministic computation. Actually Funtor does that already. Applicative and monads are just ways to sequence such computations. The former statically and the latter dynamically. Falling back to a fuzzy metaphor one can think of functor/applicative/monads as semantics machines or little embedded DSLs.