1. 10
  1.  

  2. 4

    How are Java exceptions monadic? The examples contrast two styles of exception handling. I don’t see a clear connection to the monadic laws in any of the examples. I don’t know Java, so I might be overlooking something. I do know JavaScript and I’m also confused by that section. A Promise is said to be a monad because Promise.resolve and Promise.prototype.then are equivalent to unit and bind in the very specific sense that these operators can be used to satisfy the monadic laws of identity and associativity. The monadic nature of a Promise is not related to control flow or asynchronous code execution, except perhaps incidentally. I hope I’m not being pedantic here. What the article says about Promises is much more essential for practitioners than the data structure’s theoretical context. But if the topic is Promise as monad, it seems like the relevant information is missing.

    1. 2

      My problem with the exception example is generally you would want a different user readable failure message for each error line.

      1. 2

        You can do that with monadic error handling, (see Railway-Oriented Programming) .The article is a little weird, though, in that it seems to be implying that Java exceptions are monads, which they’re not.

      2. 2

        I thought this was going to be explaining Monads using things in the kitchen or things a non-tech person would do in everyday life. I was disappointed it was just code.

        1. 2

          instance Monad Knife where