Who

Monads shmonads

Monads and exceptions are the same thing, change my mind

Obligatory background

First, what’s a monad (in programming)? 

Let’s build it up from its parts.  A “monad” is made of three things:

  1. a container, like a shopping bag,
  2. something which puts things in the container, like your mom, and
  3. another thing which takes your mom, puts her in a factory line, and forces her to put things in shopping bags as it takes them out and gives them to your other mom to put in another shopping bag.  That’s you, you’re making them do that to put food on the table, you ungrateful piece of shit. 

So a monad has three different things.  Draw a circle around them and call it a monad. 

In programming terms it’s made of:

  1. a struct (or object or whatever),
  2. a function which returns that struct (e.g., fn map(prior_contents) => struct_with_new_contents or fn transform(a:A) => struct<B>),
  3. a thing which calls those functions which return that struct using the contents of the prior functions returned struct. 

Draw a circle around them and call it a monad. 

Different on its face

The definition of a monad doesn’t sound like an exception, but under the hood for any language which uses exceptions, the language itself plays the role of #3, every method and function is #2, and every returned value or thrown exception is part of an implied #1-kind of tuple. 

Languages which expose monads instead of exceptions just put that tuple in your face.  You want that error to propagate up the stack more?  Do it yourself.  Nothing wrong with that, it’s like programming in C because you have to check for errors every time you call a function.  Unless, of course, your language has a sweet syntax to help, like zig’s _ = try your_mom().  And that’s no different from a language which implies try before every function call so you never actually type it.  Those languages just call those “exceptions,” unless you’re javascript, then they’re still called “errors” because it’s all the same when your language doesn’t differentiate between expected errors and unexpected exceptions.