1. 7
  1. 2

    I know the article states that more is coming, but I feel like it would have been good to include one or two examples of real world uses for monads that programmers face all the time. The Maybe/Option(/null) monad is something that exists in one shape or form in most languages, and many languages have introduced specific syntax for monadic bing in the form go the .? operator, which is often announced with much fanfare. Futures are another example which many languages make somewhat painful, for end up adding specific syntax for like async/wait, but these are just simple examples of monadic composition too.

    I’ve been recommending this article/talk to Haskell beginners for years who are used to other languages, which does exactly that: shows how lists/arrays, nullable types and futures are all monads, with the same andThen interface, each with very different, but consistent, behaviour: https://tomstu.art/refactoring-ruby-with-monads

    It’s great to have more articles dispelling the absurd myth that monads are difficult, they are trivial compared to a lot of abstractions people use routinely in other languages, and once you can understand the idea that higher minded types are a thing, they become very natural. Being able to write replicateM once and have it work in any monad is super useful; in IO, it’s the “do something n times” function, in futures, it’s the “fork n async things and collect the results”, in lists, it’s the “how do I make all lists of length n made up of the elements of this list” function. These all feel like very different ideas, but they all have exactly the same implementation.

    1. 1

      I don’t really see what the big deal is. A monad is just like a burrito.

      1. 2

        You have it backwards - a burrito is just like a monad.

      2. 1

        I have a contrarian position (maybe a model theoretic as opposed to a category theoretic perspective): Haskell’s do notation is a monad. Any language you can sensibly express in do notation is a monad, and the axioms about bind or the endofunctor view are implementation details.

        1. 1

          Haskell’s do notation is a monad

          Not necessarily. It can be an Applicative if you take restraint.

          And with RebindableSyntax it can be whatever the hell you need it to be.

          1. 1

            I rather meant that the linguistic features of do are the best definition of a monad: a language of sequential statement with binding and substitution.