Live data from Hacker News

Monads are monoids in the category of endofunctors

sambernheim.com

201–210 of 241 posts

Re: Monads are monoids in the category of endofunctors

#201
For me when I was learning this the first problem was to grab what Mac Lane intended to say with "monoids" exactly (in monads are monoids such that blah) since the default notion from algebra didn't match (unital semigroup). It turns out that he is speaking of monoid objects, which is a technical term as in here [1]. There it describes monoid object in a monoidal category, which is an unfortunate clash of two monoid-sounding things that need to be thought independently. One clarifies first what is the monoidal category, and only then asks what a monoid-object in that category is. In our case one starts with an arbitrary category C. The category of endofunctors has as objects functors F:C->C, and as morphisms natural tranformations mu:F1->F2. Endofunctors always compose, and that gives the endofunctor category a monoidal category structure: The monoidal product, or in other words the tensor product is the composition of endofunctors. One checks that this monoidal product verify the monoidal category axioms. So then one has established what monoidal category we talk aboout. It is in that monoidal category where one consider monoid objects, and then notices that they correspond to monads.

[1] https://ncatlab.org/nlab/show/monoid+in+a+monoidal+category

Re: Monads are monoids in the category of endofunctors

#202
post #5

Wait, a functor is just a pure unary function? And an endofunctor is just one of those where the argument type and return type are the same? This could have been explained to me years ago, in five minutes? Sometimes it makes me mad that so much confusion (and as another commenter put it, gatekeeping) has been sown in FP circles through the invention of pointlessly-obfuscated terminology for everything (and through -…

> It's like when the medieval Catholic Church refused to print a bible in anything but Latin so that they'd remain the sole authority on its content.

I'd say reading the Bible, or any other deep philosophical/spiritual text in a translation is almost an utter waste of time (unless that actually helps you psychologically, then it is not), if not harmful.

The original words and phrasing with all their possible meanings make a huge lot more sense than specific translations.

Something that sounds banal or weird can actually mean something entirely different and deep once you carefully analyze the original words.

It is, however, important to remember Latin is not the original for the Bibile. But it still has a lot of what has been lost in many other translations.

Re: Monads are monoids in the category of endofunctors

#203
post #61

Earlier quoted context omitted.

So you would say the same for programming in general then? Should programmers not use the word "function" because that word is foreign to non-programmers and might push them away?

It's tricky with functional programming. It's like reading SICP, and after a lot of effort, y-combinators and stuff, the outcome is like "See? Thanks to this invention, we can easily pass multiple parameters into a function". Which is fun, but not anything that will impress a non-functional programming user.

This is not an unusual thing to see around foundations of mathematics, either - where it could take dozens of pages filled with complicated argument and construction before one eventually can say, “We can multiply these integers now!”

Re: Monads are monoids in the category of endofunctors

#204

There’s a few gaps in this explanation that my deductive completionist brain is looking for. Namely, I’m wondering what kind of thing is even capable of being a monoid and an endofunctor at the same time. Mathematically, a monoid is a set (or collection to be more general) closed under a binary operator (the monoidal product) and with a distinguished identity element. An endofunctor is a mapping from a category to it…

The categorical definition of a monoid is different than the usual algebraic one (although one can be recovered from the other) and usually treats a monoid as a single object (hence "mono-"). In particular, usually a monoid is defined as a single object category (sometimes a "monoid object" is defined inside a category, but that's a different presentation). The usual multiple objects of an algebraic monoid correspond…

A monoid is a certain kind of object (potentially one of many) in a certain kind of category (called “monoidal” category).

Re: Monads are monoids in the category of endofunctors

#205

Earlier quoted context omitted.

Mathematically the main thing stopping it from being a function is that categories are typically too big to be a set. Otherwise they're pretty much the same as a function. The whole type thing is just something Haskell does, it's not something that's meaningful for general categories.

Not really, mathematically a functor is really two "functions," one mapping objects to objects and one mapping morphisms to morphisms, along with some conditions that make sure the functor is "structure preserving." It is fundamentally a type level construct because, as it is applied to programming, the category in question is the category of types (which is not technically a category due to the halting problem but w…

Sure a functor satisfies more conditions but that doesn't make it less of a function. Heck if you restrict it to mapping a single set of objects or a particular Homset it is a function, you just can't extend this to the whole category if the objects form a proper class (which happens fairly often).

The whole distinction between value-level or type-level is meaningless in general categories. Sure there's a distinction between morphisms between objects and functors between categories but you've also got the category of categories where the morphisms are functors between categories.

Edit: I'll have to concede that the article confuses them too much though, you can't just pick a random function and declare it to be a functor, especially when it's not clear between which categories.

Re: Monads are monoids in the category of endofunctors

#206
post #24

This post is very wrong. Being a monoid in the category of endofunctors means something very different from being a monoid in the normal sense (they're related in a category-theoretic way, but the similarity is at a very abstract level). Simple sequences have a lot of structure which mean they are a lot of different things; it is true that sequences are all of monads, functors, and monoids, but the latter structure i…

The article is just proving what we all know for a long time about Monads:

https://twitter.com/randyshoup/status/992773186239516677?lan...

Re: Monads are monoids in the category of endofunctors

#208
So we cannot talk about a type being monad without also saying under what function?

E.g. Arrays are monads under concatenation. So why people then say easily "Option type is monad" without stating under which operation? I assume Option is monad under "all" and "any" function, but not sure.

Re: Monads are monoids in the category of endofunctors

#209
post #24

This post is very wrong. Being a monoid in the category of endofunctors means something very different from being a monoid in the normal sense (they're related in a category-theoretic way, but the similarity is at a very abstract level). Simple sequences have a lot of structure which mean they are a lot of different things; it is true that sequences are all of monads, functors, and monoids, but the latter structure i…

> means something very different from being a monoid in the normal sense

Yet you didn't say how exactly different. I understand I probably need to know category theory for that, yet nevertheless OP's post was useful, fulfilled some curiosity, but your comment didn't, besides leaving feeling "it's complex", sorry.

I'd really appreciate if someone one day wrote as clear explanation of monads as OP's, but at the same time staying correct.

Re: Monads are monoids in the category of endofunctors

#210

So we cannot talk about a type being monad without also saying under what function? E.g. Arrays are monads under concatenation. So why people then say easily "Option type is monad" without stating under which operation? I assume Option is monad under "all" and "any" function, but not sure.

Yes, but its usually obvious which one is meant, so you don't bother saying under what operation. Option is a monad under the same concatenation as Array, just think of them as arrays that always have length 0 or 1.
Post reply on HN