this post was submitted on 11 Oct 2025
274 points (96.3% liked)

Programmer Humor

27193 readers
985 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
top 26 comments
sorted by: hot top controversial new old
[–] sirico@feddit.uk 33 points 3 weeks ago* (last edited 3 weeks ago) (2 children)

God, you guys are idiots, it's so simple

  • You take a Function
  • ?????
  • Result It can't be simpler /s

No joke that's pretty much every example I came across trying to get my head around it :D.

Not sure if using analogies is helpful or just going to be more confusing but, the way I think of a monad is similar to how I used to cook back when I worked in restaurants. I’d prep all my ingredients in small containers so I wouldn’t forget anything, and they’d be ready to go when needed. Then I’d start adding them to the main mixing bowl, one step at a time. If I forgot an ingredient or accidentally flipped the bowl, the recipe would fail — you can’t keep baking after that.

So a monad is like that bowl: if you mess up, it just dumps everything out and resets your little prep bowls, instead of letting you keep going and make a batch of shitty cookies

The “main-bowl” is the monad (the context that holds your values).

The “prep bowls” are the individual values or functions ready to be chained.

The “dump/reset” is the idea that once something goes wrong, the chain stops safely.

And “shitty cookies” are the result of not putting a monad in place and just sending it.

Maybe someone with a more diverse programming background can explain it better. But it's basically a function checker usually wraped in IF ELSE and RETURN.

Some pseudo code in case my analogy doesn't make sense.

def main():
    bowl = get_flour()
    bowl = add_butter(bowl)
    
    if bowl is None:
        return "Recipe failed — restart!"

    bowl = add_sugar(bowl)
    
    if bowl is None:
        return "Recipe failed — restart!"

    return bake(bowl)
[–] Pyro@programming.dev 4 points 3 weeks ago (2 children)

Isn't your example just the builder pattern?

[–] Kache@lemmy.zip 9 points 3 weeks ago* (last edited 3 weeks ago)

Yeah, that explanation is missing the critical point of generically applying external functions through flat_map/bind

I think this is a good explanation: https://fsharpforfunandprofit.com/rop/

[–] marcos@lemmy.world 3 points 3 weeks ago (1 children)

A monad is a builder that lets you use previous partial results to make decisions while you build.

[–] WhyJiffie@sh.itjust.works 2 points 3 weeks ago (1 children)

that sounds like a regular builder

[–] marcos@lemmy.world 1 points 3 weeks ago

If you regular builders can't be composed as values...

That may be regular, but it doesn't make them good. Some times you need that, and it's ok, but that shouldn't be most times.

[–] camr_on@lemmy.world 4 points 3 weeks ago

I like your explanation, that makes a lot of sense

[–] mEEGal@lemmy.world 18 points 3 weeks ago (8 children)

Seriously, can someone please explain monads like we're dumb or something ?

[–] magic_lobster_party@fedia.io 7 points 3 weeks ago

It’s like a burrito

[–] someacnt@sh.itjust.works 5 points 3 weeks ago

Monad is (a classes of type of) a collapsible container. Collapsible, like how you can flatten a nested list, or Option<Option> can be flattened to Option.

A common pattern with monads is the flatMap function, where you apply function A -> List to (each element of) List to obtain List. This happen to represent erroneous call chaining with Option or Result types.

[–] nik9000@programming.dev 3 points 3 weeks ago

I'm not good at this but that's never stopped me from making a fool of myself before.

Iterators are monads because they have a flatMap on them. It takes each element and spits out a new iterator which is merged in to the result.

Option is a monad too. Same reason. You can map the contents to another option. And you won't get called if there's nothing inside.

Promises are monads too. You can map the result to another promise. The wrinkle here is that you don't get to know when the map happen. Or it might not get called at all if the promise errors out.

IO can be a monad because you can ask it for input and wait for the result. It's just the same as a promise.

See how these different things share a common behavior? That's monad. Or, maybe it's monoid. Names are hard and I'm busy making a fool of myself.

Monads are nothing more than a useful abstraction. Haskell is famous for them because they couldn't make Haskell do imperative stuff without them so they spread them all over the language.

We all use them every day in regular programming. We just don't think of them as a class of thing.

[–] me@social.jlamothe.net 3 points 3 weeks ago

@mEEGal @ZILtoid1991 Honestly, the best way I've found to understand monads (if we're talking Haskell) is to look at the type signatures of its functions. Understanding return, (>>=), and (>>) will essentially tell you everything you need to know.

[–] Kache@lemmy.zip 2 points 3 weeks ago

Here: https://fsharpforfunandprofit.com/rop/

A very practical and tangible walkthrough

[–] bss03 2 points 3 weeks ago

http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html

It's a "programmable semicolon" or "decorated-function composition". I think most people that are confused about it, are trying to make it be more meaningful than it is. Haskell (?) just grabbed a math name so they'd have one word for it, because it's a useful class name there.

[–] leftzero@lemmy.dbzer0.com 16 points 3 weeks ago (1 children)

Do you know C#? LINQ? IEnumerable? IEnumerable is a monad. That's how LINQ works.

You've been using monads all along.

[–] magic_lobster_party@fedia.io 12 points 3 weeks ago (1 children)

Or for those using Java: Stream is a monad

[–] pegazz@lemmy.world 7 points 3 weeks ago (1 children)

Optional is my favorite example to give, at this point most people have internalized how to use its map function and how it works

[–] magic_lobster_party@fedia.io 3 points 3 weeks ago

That’s a good one.

A rule of thumb is that if it has map and flatMap (or equivalent), then chances are that it’s a monad.

[–] dreadbeef@lemmy.dbzer0.com 11 points 3 weeks ago

Monads are just a monoid in the category of endofunctors. If you dont understand that, skill issue

Tap for spoiler/s

[–] rikudou@lemmings.world 7 points 3 weeks ago

I know! That's the Greek mythology thing.

[–] Klear@quokk.au 3 points 3 weeks ago* (last edited 3 weeks ago)

You should crosspost this to !philosophymemes@quokk.au

[–] olafurp@lemmy.world 1 points 3 weeks ago (2 children)

Isn't it just like error handled code in Golang?

Like a sequence A, B, C where if A errors you don't continue to B or C but if A is ok then you just continue doing B and so on. In the end you end up with the result or errors. Am I wrong to assume this?

[–] ytg@sopuli.xyz 2 points 3 weeks ago

The Either monad (also known as Result) provides Go-like error handling, but automated. You only check manually for errors after the last call, the monad handles the process.

But this is just one example of a monad, there are many more.

[–] Solemarc@lemmy.world 1 points 3 weeks ago

Whenever I try and get a proper explanation of a monad from the internet I get these miserable opaque examples which make me go "sorry I asked!" But I think a monad is basically just single type that when unwrapped gives you the result of a calculation and some metadata about the calculation.

I think it's more like Rust's Result or Option types then go's tuples but I'd say they both basically count.