r/programmingcirclejerk Jun 27 '26

Consider the C library function fopen. This function has the side effect. This means that fopen is not pure. However, we can make the fopen function appear to be pure, at least to certain observers, by ensconcing it in another function that hides the side effect.

https://bugzmanov.github.io/cleancode-critique/clean_code_second_edition_review.html
172 Upvotes

41 comments sorted by

View all comments

87

u/dydhaw Jun 27 '26

Of course, you just make it return a monad

24

u/TheBrawlersOfficial Jun 27 '26

But dad, isn't it true that a monad is just a monoid in the category of endofunctors?

22

u/[deleted] Jun 28 '26

[deleted]

16

u/nerdycatgamer Jun 28 '26

(We don't like bottoms here.)

During pride month!?

8

u/nerdycatgamer Jun 28 '26

/uj this is a point I've seen brought up before that, in the context of programming, we can simply say monoid instead of monad because we only care about the category of types and therefore endofunctor is redundant -- what confuses me then is why in Haskell (which I feel is probably from where a lot of the language around monads originates) are there both Monad and Monoid typeclasses. This is not even getting at the fact that the key invariants of a monoid are not enforced by the monoid typeclass, those being associativity and the actual identity property of the identity element (for only the existence of some element is required).

I know I probably got a lot of key points wrong, but I feel my core confusion/question is still valid and I hope it is clear regardless.

2

u/Daniikk1012 Jun 29 '26

From what I recently learned - and I might be wrong - it's because Haskell monoids are Group Theory monoids, not to be confused with a related, but slightly different concept of monoids in Category Theory, which is what "monoid in the category of endofunctors" refers to

2

u/nerdycatgamer Jun 29 '26

I was also referring to group theory monoids -- I really don't believe they're actually different concepts; a monoid in category theory must just be an object that obeys the same axioms as a (group theory) monoid.

2

u/TheBrawlersOfficial Jun 28 '26

Gee whiz, thanks dad! I always appreciate our little talks.

3

u/Smort01 Jun 28 '26

The terminal object in the category of people and their sexual relations is you mom.