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
you are viewing a single comment's thread
view the rest of the comments
[–] 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)
[–] camr_on@lemmy.world 4 points 3 weeks ago

I like your explanation, that makes a lot of sense

[–] 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.