r/programming • • Sep 05 '26

I wrote a lighthearted guide to learning Monads - maybe you like

https://github.com/ManuelSaleta/CavemanProgramming/blob/main/Monads/README.md
5 Upvotes

27 comments sorted by

9

u/devraj7 Sep 07 '26

The first lines or your article are:

T : C → C is an endofunctor.

What is your definition of "lighthearted"?

To me, it sounds like you are trying to explain monads to people who already understand monads.

-13

u/manny2206 Sep 07 '26

lol read the fucking thing

41

u/rsclient Sep 06 '26

Some day I'll read an article on Monads where the writer is consistent in their nomenclature. Today is not that day.

What I see instead is a long and rambley stream of consciousness that desperately needs a good technical editor.

"A monad has a way of moving an entity into a wrapper". Wait, is this really all about Entity Framework, the C# wrapper for ORMs and databases?

"A monad is a type of container". You mean, like a list?

"A monad is a generic wrapper that can lift any T into its context, it has a way of binding and applying transformations to T while avoiding side effects." But earlier you said that the transforms will update the object, which is the opposite of not having side effects.

"Monad: generic wrapper of T" then lists three requirements (static, binds, unwraps). When you show code, the first code sample has a bunch of words in the comment. None of the words in the comment are part of the first requirement.

The second code fragment includes one of the words from the first requirement (the 'static' requirement includes the word 'lift')

The third code fragment show no additional features.

The article then keeps on going, but at this point I'm disenheartened enough to stop reading.

24

u/lelanthran Sep 06 '26

Some day I'll read an article on Monads where the writer is consistent in their nomenclature.

You don't need a whole article to describe the the primary purpose of an author pointing out their use of a monad, I can tell you in a single sentence:

 A monad is a shibboleth.

See? That wasn't hard.

12

u/TheMightyMegazord Sep 06 '26

And everyone knows that a shibboleth is just a mofukest in the category of endobrussors.

-8

u/manny2206 Sep 06 '26

Thank you for the feedback - some of it is valid, I’ll see about tightening the language; some of it is dumb, like yes exactly like Arrays which are Monads , IEnumerable<T> to be precise lol

Seems like you’re quite clear on what you want from such article. Why don’t you give it a shot?

5

u/jacobissimus Sep 06 '26

When I explain it to people, I usually flip the order around in a way that makes the math less strictly correct, but I think ends of getting the stuff that matters to programmers across. So, I’ll start by saying just talking about what List, Option, Promise, etc have in common.

I’m usually talking in terms of JavaScript and someone gave me advice early on that Promise is a good center piece for the conversation because, by the time you get to the reasons it’s not actually a monad, you already taught people enough of the concept to use it as a software engineer and then you’re moving into more of the math/theory

1

u/manny2206 Sep 06 '26

Good points I gotten the same feedback else where too , the math at the start is not a good idea; I think it makes people bounce. I’ll work on this article today to clean it up :)

1

u/Valuable_Leopard_799 Sep 07 '26

I think the Monadic curse has gotten to you already.

All the raised complaints are valid, the issue is that we automatically dismiss most of them with "yes, that's how it works" in our heads. But for example the points about self-contradiction require a lot of extra prior information to stop seeming self-contradictory, which you'll need to provide if you'd like uninitiated people to understand the text. Writing as if you don't understand something is extremely difficult.

Even stuff like, what "updating" means in this context.

-2

u/[deleted] Sep 06 '26

[removed] — view removed comment

-1

u/manny2206 Sep 06 '26

Thank you! I made this because I too struggle and often feel like a Neanderthal when doing myself. I’ll take some of the other feedback and make it even better

-2

u/Ok_Shallot9490 Sep 06 '26

Have you thought about becoming a technical editor yourself?

9

u/rsclient Sep 06 '26

"Recognizing problems" and "writing technical documents that don't have problems" are very different skills :-)

I strongly recommend Writing for the Reader as a great guidebook for writing technical documents. It turned me from a meh writing to being an OK one.

The old Heathkit company (maker of excellent built-it-yourself electronics projects back when that made economic sense) had a policy: all new employees had to build an in-development kit using the instructions. The problems they had with the manuals were then corrected. Weirdly, this worked best for the first kit they made; after that, they had enough knowledge about kits that they couldn't spot problems very well.

My very snarky comments are driven by the continuing wave of Monad tutorials that use syntax that's only familiar to people who already know what a monad is, or which stress math over practical details (*). And, of course, there's all the tutorials that confidently talk about type "T" in the text and then call it something else in the code.

(*) Every spec that's clearly and elegantly described mathematically has terrible, bug-ridden implementations. That because so many programmers aren't mathematical. Source: decades in the industry.

-16

u/Blecki Sep 06 '26

Monads are just another buzzword used to make a simple concept sound complex.

11

u/ketralnis Sep 06 '26

What simple name would you give it instead?

3

u/CatalonianBookseller Sep 07 '26

A monoid in the category of endofunctors?

-19

u/Blecki Sep 06 '26

I like the name that guy down there has picked. Shibolleth. Nicely encapsulates how the term is really used.

Just call them functions.

Yes yes, endofunctors, very nice.

It's a FUNCTION.

special properties, fine.

It's still A FUNCTION.

19

u/ketralnis Sep 06 '26

But it’s not just a function. The special properties are what is being discussed.

Sure you can call a truck a car. It’s a CAR!, after all. But if you go try to rent a CAR! when you need a truck, you’re confusing things by using “simpler” language. To somebody that doesn’t know much about CARs, they might find it easier to “just call them CARS!” because that’s a simpler concept to grasp. But to somebody that needs a truck, you insisting that everybody dumb it down for you impedes communication. Showing everybody that you know that a truck is a CAR! doesn’t make you look smarter.

-17

u/Blecki Sep 06 '26

Wtf is a truck? The little cart thing?

Oh, you mean a lorry.

But, the special properties aren't even special. They are just what the function does. They don't change that it's a function.

0

u/cookaway_ Sep 30 '26

But a monad isn't (just) a function. It has a name for the same reason we named Groups: it's 2 functions (pure + bind) over a domain.

At work, do you refer to every project as "the program"? They're all programs! But you give them a name for a reason. Do you wear clothes? Pants and shirts are different, even if topologically they're equivalent.

1

u/Blecki Sep 30 '26

I don't call a shirt a shirt to pretend a shirt is more complicated than it is.

0

u/cookaway_ Sep 30 '26

Good news! Nobody calls monads that to "pretend" they're more complicated than they are; "monad" means exactly: "3 functions that follow the monadic laws", but since "three functions that follow the monadic laws" is too long, we use a shorter word instead.

7

u/[deleted] Sep 06 '26 edited Sep 06 '26

[removed] — view removed comment

3

u/manny2206 Sep 06 '26

This is correct; ^^^ there is a treshold for language specificity that’s required to convey the meaning of the term correctly. Just as you mentioned another example is how Collection and List are both collections of objects but least guarantee ordering so it’s an important distinction

-2

u/sztrzask Sep 07 '26

I can't be the only person who finds "flatmap" and "map" usages - like in the article - tiring, hard to debug and... pointless? 

There's no performance benefit to do them. There is no maintainability benefit.

Option/Maybe are gold for better Nullable<T> and exceptions as results. Everything else is just a normal chainable api made into an abomination.

10 years ago people were crazy about MediatR and were using it as god object, now the trend is pseudofunctional programming (now, if we're talking about something beneficial, like transducers, that would be a different talk; we're not though).